How to fix Error: An output value is not allowed here in Terraform

TerraformBEGINNERMEDIUMUpdated Dec 30, 2025· 98 views

This error occurs when an output block is placed in an invalid location within your Terraform configuration. Output blocks must be defined at the root level of your Terraform files, not nested inside resource, data, module, or other configuration blocks.

Quick fix

Fixes Error: An output value is not allowed here

# Example of incorrect nesting (WRONG)
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  
  output "instance_id" {  # ERROR: output inside resource
    value = self.id
  }
}
  1. Identify the problematic output block
  2. Move the output block to the root level
  3. Check for missing closing braces
  4. Validate and format your configuration
terraform — error
# Example of incorrect nesting (WRONG)
resource "aws_instance" "web" {
ami = "ami-12345678"
instance_type = "t2.micro"
output "instance_id" { # ERROR: output inside resource
value = self.id
}
}
Error: An output value is not allowed here

What this error means

Terraform enforces strict syntax rules about where output blocks can appear in your configuration. An output block declares a value that Terraform will expose after applying your infrastructure. These blocks must exist at the root level of your .tf files—the same level where you write resource, data, and variable blocks. When the parser encounters an output block nested inside another block (like inside a resource definition), it rejects it as a syntax error because outputs are top-level constructs in HCL (Terraform's configuration language).

Typical symptoms

  • Terraform shows 'An output value is not allowed here' error during plan or apply
  • Error message points to a specific line number in your .tf file
  • The problematic line contains the output keyword inside another block
  • Syntax highlighting in your editor might not show mismatched braces
  • terraform fmt or terraform validate catches the error

Common causes

  1. An output block is accidentally nested inside a resource, data, module, or other configuration block
  2. A missing closing brace } causes Terraform to think later output blocks are nested inside a resource
  3. Copy-pasting configuration created incorrect nesting or indentation
  4. Editor's auto-completion or formatting accidentally moved an output block inside another block
  5. Incorrect configuration structure where output is indented as if it's part of a parent block

How to fix "Error: An output value is not allowed here"

1Identify the problematic output block

Terraform's error message includes the line number where the output block appears. Open that .tf file and locate the output block:

hcl
# Example of incorrect nesting (WRONG)
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  
  output "instance_id" {  # ERROR: output inside resource
    value = self.id
  }
}

In this example, the output block starts on the line with the error.

2Move the output block to the root level

Cut the output block and paste it at the root level of your Terraform file (same indentation level as resource, data, and variable blocks):

hcl
# Correct placement
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
}

output "instance_id" {  # Correct: at root level
  value = aws_instance.web.id
}

The output block should have zero indentation (or consistent with your other root-level blocks).

3Check for missing closing braces

If you have a resource or block that should have closed earlier, verify all closing braces are in place:

hcl
# WRONG: Missing closing brace for resource
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  # Missing } here

output "instance_id" {  # Error: parser thinks this is inside resource
  value = aws_instance.web.id
}
}

# CORRECT: All braces matched
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
}  # Closing brace for resource

output "instance_id" {
  value = aws_instance.web.id
}
4Validate and format your configuration

Run Terraform's validation and formatting tools to catch and fix syntax issues:

bash
# Validate syntax
terraform validate

# Auto-format your .tf files (fixes most indentation issues)
terraform fmt -recursive

terraform fmt will reformat your files to correct indentation and structure. This often automatically fixes output placement issues.

5Review block structure in your editor

Use a code editor with HCL syntax support to visualize block structure:

- Visual Studio Code with HashiCorp Terraform extension
- Terraform extension shows brace matching and nesting
- Enable "bracket pair colorization" to see matching braces
- Use the outline/symbols panel to see all root-level blocks

This helps identify if output blocks are accidentally indented or inside other blocks.

Advanced notes

Terraform's HCL parser is strict about block location because outputs have special meaning in the execution model. During the planning phase, Terraform determines which outputs exist and their values. Outputs must be at the module level (root or inside a module definition) to be properly recognized by Terraform's execution engine. This is different from some configuration tools that allow outputs anywhere—Terraform enforces this because outputs are part of the module's public API. In modules, outputs should be in the module's .tf files at the root level of that module directory. If you're writing a module with outputs, ensure all output blocks in the module are at the root of the module directory, not nested inside resources.

Frequently asked questions

What does "Error: An output value is not allowed here" mean?
Terraform enforces strict syntax rules about where output blocks can appear in your configuration. An output block declares a value that Terraform will expose after applying your infrastructure. tf files—the same level where you write resource, data, and variable blocks.
How do I fix "Error: An output value is not allowed here"?
This error occurs when an output block is placed in an invalid location within your Terraform configuration. Output blocks must be defined at the root level of your Terraform files, not nested inside resource, data, module, or other configuration blocks.
What causes "Error: An output value is not allowed here"?
An output block is accidentally nested inside a resource, data, module, or other configuration block A missing closing brace } causes Terraform to think later output blocks are nested inside a resource Copy-pasting configuration created incorrect nesting or indentation
Is the "Error: An output value is not allowed here" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading