How to fix Error: Expected attribute terminator in Terraform

TerraformBEGINNERHIGHUpdated Dec 30, 2025· 156 views

The Expected attribute terminator error occurs when Terraform's HCL parser encounters invalid syntax in a resource or block attribute definition. This typically happens due to missing commas, incorrect quotation marks, or improper line breaks. Fix it by reviewing your configuration syntax carefully using terraform validate.

Quick fix

Fixes Error: Expected attribute terminator

terraform validate
  1. Run terraform validate to identify the exact error
  2. Check for missing commas between attributes
  3. Verify quotation marks are properly closed
  4. Check for matching braces and brackets
terraform — error
terraform validate
Error: Expected attribute terminator

What this error means

This error occurs when Terraform's HCL parser encounters a syntax error while parsing resource or block attributes. The parser expects a specific terminator (usually a comma or closing brace) after an attribute definition but finds something unexpected instead. The "Expected attribute terminator" error is a parsing-level syntax error that indicates malformed HCL. Common causes include missing commas between attributes, unclosed strings or brackets, improper indentation in YAML-like blocks, or using invalid characters in attribute values without proper quoting. This is typically caught by terraform validate before any infrastructure changes are attempted, making it a configuration syntax issue rather than a resource creation problem.

Typical symptoms

  • Terraform returns "Expected attribute terminator" error during terraform validate, plan, or apply
  • Error message points to a specific line number in your configuration file
  • The problematic line appears to have valid-looking attribute syntax
  • Configuration validation fails immediately without attempting to parse further
  • Error occurs when adding or modifying resource attributes
  • Similar configurations work fine in other files or previous versions

Common causes

  1. Missing comma between consecutive attributes in a resource or block definition
  2. Unclosed or mismatched quotation marks around attribute values
  3. Unmatched or incorrectly nested braces, brackets, or parentheses
  4. Using tabs instead of spaces for indentation in nested blocks
  5. Invalid characters in unquoted attribute values (e.g., special symbols, colons without string context)
  6. Line break in the middle of a string value without proper string continuation
  7. Incorrect syntax in map or list definitions without proper closing brackets

How to fix "Error: Expected attribute terminator"

1Run terraform validate to identify the exact error

Start by validating your configuration to get the precise line number where the error occurs:

bash
terraform validate

The output will show you the exact file and line number where the parser encountered the unexpected token. This is the most important diagnostic step.

2Check for missing commas between attributes

The most common cause is a missing comma between resource attributes. Each attribute must be separated by a comma:

hcl
# Wrong - missing comma after name
resource "aws_instance" "example" {
  ami           = "ami-12345"
  instance_type = "t2.micro"
  tags = {
    Name = "example"
  }
}

# Correct - comma between attributes
resource "aws_instance" "example" {
  ami           = "ami-12345"
  instance_type = "t2.micro",
  tags = {
    Name = "example"
  }
}

Note: Top-level attributes in resources and data sources may have optional trailing commas, but between attributes they are required.

3Verify quotation marks are properly closed

Ensure all string values have matching opening and closing quotation marks:

hcl
# Wrong - missing closing quote
resource "aws_instance" "example" {
  ami = "ami-12345
  instance_type = "t2.micro"
}

# Correct - properly quoted strings
resource "aws_instance" "example" {
  ami           = "ami-12345"
  instance_type = "t2.micro"
}

Also check for mixed quote types (opening with double, closing with single, or vice versa).

4Check for matching braces and brackets

Ensure all opening braces, brackets, and parentheses have corresponding closing ones:

hcl
# Wrong - missing closing brace
resource "aws_instance" "example" {
  tags = {
    Name = "example"
    Environment = "prod"
}

# Correct - all braces closed
resource "aws_instance" "example" {
  tags = {
    Name = "example"
    Environment = "prod"
  }
}

Use your editor's bracket matching feature to identify mismatches.

5Verify correct indentation and use spaces (not tabs)

Terraform requires consistent indentation using spaces, not tabs. Mixing tabs and spaces can cause parsing errors:

hcl
# Use 2 or 4 spaces consistently
resource "aws_instance" "example" {
  ami           = "ami-12345"
  instance_type = "t2.micro"
}

# Also works with 4 spaces
resource "aws_instance" "example" {
    ami           = "ami-12345"
    instance_type = "t2.micro"
}

Configure your editor to use spaces and to display whitespace characters so you can spot tabs.

6Quote attribute values that contain special characters

If an attribute value contains colons, dashes, or other special characters, wrap it in quotes:

hcl
# Wrong - colon without quotes
ami = ami:123:456

# Correct - special characters quoted
ami = "ami:123:456"
description = "This is a description with: colons and - dashes"

When in doubt, quote your values. Terraform will treat quoted strings as literals.

7Check for proper map and list syntax

Maps and lists have specific syntax requirements:

hcl
# Wrong - missing comma in map
tags = {
  Name = "example"
  Env = "prod"
}

# Correct - comma between map entries
tags = {
  Name = "example",
  Env = "prod"
}

# Correct - list syntax (comma-separated values in brackets)
subnets = ["subnet-123", "subnet-456", "subnet-789"]
8Use terraform validate after each fix

After making corrections, run terraform validate again to confirm the syntax error is resolved:

bash
terraform validate

If fixed correctly, you should see "Success! The configuration is valid."

Advanced notes

The "Expected attribute terminator" error is specifically a HCL parser error. The parser is a state machine that expects specific tokens in a specific sequence. When it encounters an unexpected token (typically something other than a comma or closing delimiter), it throws this error.

Some configuration editors and IDEs can catch these errors before you run terraform validate by highlighting syntax issues as you type. Using an editor extension for Terraform/HCL (such as the HashiCorp Terraform extension for VS Code) can help you spot these issues earlier.

For complex configurations with deeply nested structures, breaking your configuration into multiple files with clear separation of concerns can make syntax errors easier to spot. You can also use terraform fmt to automatically format your configuration files according to Terraform conventions.

If you encounter this error in generated or templated Terraform code, check that your generation logic is properly escaping quotes and maintaining correct syntax. Template generators are a common source of subtle syntax errors.

Frequently asked questions

What does "Error: Expected attribute terminator" mean?
This error occurs when Terraform's HCL parser encounters a syntax error while parsing resource or block attributes. The parser expects a specific terminator (usually a comma or closing brace) after an attribute definition but finds something unexpected instead. The "Expected attribute terminator" error is a parsing-level syntax error that indicates malformed HCL.
How do I fix "Error: Expected attribute terminator"?
The Expected attribute terminator error occurs when Terraform's HCL parser encounters invalid syntax in a resource or block attribute definition. This typically happens due to missing commas, incorrect quotation marks, or improper line breaks. Fix it by reviewing your configuration syntax carefully using terraform validate.
What causes "Error: Expected attribute terminator"?
Missing comma between consecutive attributes in a resource or block definition Unclosed or mismatched quotation marks around attribute values Unmatched or incorrectly nested braces, brackets, or parentheses
Is the "Error: Expected attribute terminator" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading