This error occurs when you reference an attribute that does not exist on a Terraform resource, data source, or module output. Common causes include typos in attribute names, missing .outputs in remote state references, and version incompatibilities.
Terraform is trying to access an attribute on a resource, data source, or module that is not defined or exported. This happens when you reference an attribute name that does not exist, or when you use incorrect syntax to access nested attributes. The error can also occur when referencing remote state outputs without the required .outputs path, or when using resources configured with count or for_each without the proper index syntax.
Open the Terraform provider documentation for your resource type and verify the exact spelling and nesting of the attribute you are trying to access. Provider documentation is available at https://developer.hashicorp.com/terraform/language/resources or the specific provider docs (aws, azurerm, google, etc.). Attributes are case-sensitive and must match exactly.
In Terraform 0.12+, when accessing outputs from terraform_remote_state, you must include the .outputs path. Change:
data.terraform_remote_state.example.my_outputTo:
data.terraform_remote_state.example.outputs.my_outputThis is required because outputs are nested under the outputs attribute.
When you modify module variables or outputs, Terraform may use cached schema information. Clear the cache and reinitialize:
rm -rf .terraform
terraform initThen run terraform plan or apply again. This ensures Terraform reads the latest module definitions.
When a resource uses count, you must access specific instances:
aws_instance.example[0].id # Access first instanceFor resources with count=0, use conditional logic:
resource_id = var.create_instance ? aws_instance.example[0].id : nullWithout the index, Terraform treats count resources as lists.
When a resource uses for_each, access specific instances with the key:
aws_instance.example["web"].id # Access instance with key "web"You cannot reference a for_each resource without specifying the key. If you need all instances, use splat syntax:
[for k, v in aws_instance.example : v.id]To expose a resource attribute from a module, define an output block in the module's outputs.tf:
output "instance_id" {
description = "The ID of the instance"
value = aws_instance.example.id
}Then in your parent configuration:
module "compute" {
source = "./modules/compute"
}
output "app_instance_id" {
value = module.compute.instance_id
}Each level must explicitly define the output being referenced.
When upgrading providers or Terraform versions, attribute names sometimes change or are deprecated. If you get this error after an upgrade, check the provider changelog for breaking changes. Use terraform console to interactively explore available attributes on resources and verify correct syntax before running apply. Some attributes are conditional and only exist when specific configuration blocks are present (e.g., aws_s3_bucket.website_domain only exists when the website block is configured).
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform