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.
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.
Start by validating your configuration to get the precise line number where the error occurs:
terraform validateThe output will show you the exact file and line number where the parser encountered the unexpected token. This is the most important diagnostic step.
The most common cause is a missing comma between resource attributes. Each attribute must be separated by a comma:
# 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.
Ensure all string values have matching opening and closing quotation marks:
# 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).
Ensure all opening braces, brackets, and parentheses have corresponding closing ones:
# 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.
Terraform requires consistent indentation using spaces, not tabs. Mixing tabs and spaces can cause parsing errors:
# 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.
If an attribute value contains colons, dashes, or other special characters, wrap it in quotes:
# 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.
Maps and lists have specific syntax requirements:
# 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"]After making corrections, run terraform validate again to confirm the syntax error is resolved:
terraform validateIf fixed correctly, you should see "Success! The configuration is valid."
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.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform