terraform Errors
37 error patterns
Terraform state created by newer version
Error: state snapshot was created by Terraform v.*, which is newer than current
- •Upgrade Terraform CLI to match or exceed the version in state
- •Use tfenv to manage multiple Terraform versions
Terraform state lock cannot be acquired
Error acquiring the state lock.*Lock Info.*ID:
- •Run 'terraform force-unlock <LOCK_ID>' if previous run crashed
- •Check if another team member has a running terraform operation
Terraform resource exists but not in state
Error: Resource already exists.*import
- •Use 'terraform import <resource_address> <id>' to import existing resource
- •Use import blocks in Terraform 1.5+: import { to = ... id = ... }
Terraform moved block target doesn't exist
Error: Moved block.*does not match any resource
- •Verify the 'to' address in moved block matches new resource address exactly
- •Run 'terraform plan' to see current state addresses
Terraform dependency lock file inconsistent
Error:.*inconsistent dependency lock file.*terraform init.*-upgrade
- •Run 'terraform init -upgrade' to update the lock file
- •Delete .terraform.lock.hcl and run 'terraform init' to regenerate
Terraform unsupported attribute reference
Error:.*Unsupported attribute.*This object has no argument.*attribute.*named
- •Check provider documentation for correct attribute names
- •Upgrade provider version that may have added the attribute
Terraform dependency cycle detected
Error:.*Cycle:.*depends on.*depends on
- •Break the cycle by using depends_on explicitly on one side
- •Extract shared configuration into a separate module
Terraform provider inconsistent result after apply
terraform.*Error:.*Provider produced inconsistent result after apply
- •This is usually a provider bug - report to provider maintainers
- •Try terraform apply again (may succeed on retry)
Terraform for_each with unknown value
terraform.*Error:.*for_each.*depends on resource attributes that cannot be determined
- •Use -target to apply the dependency first, then full apply
- •Move the dynamic value to a local with a known set of keys
Terraform backend configuration changed
terraform.*Error:.*Backend configuration changed.*terraform init.*-reconfigure
- •Run 'terraform init -reconfigure' to reinitialize backend
- •Use 'terraform init -migrate-state' to move state to new backend
Terraform provider not found in registry
terraform.*Error:.*Provider.*registry\.terraform\.io.*could not be found
- •Check provider source path: required_providers { name = { source = '...' } }
- •Run 'terraform init' to download the provider
Terraform count depends on unresolvable value
terraform.*Error:.*value of.*count cannot be computed
- •Use a data source or variable for count instead of computed attribute
- •Split into two applies: first create the dependency, then use count
Terraform tainted resource requires replacement
terraform.*Error:.*resource.*tainted.*must be replaced
- •Run 'terraform apply' to replace the tainted resource
- •Use 'terraform untaint <resource>' to remove taint if not needed
Terraform cannot destroy resource with deletion protection
terraform.*Error:.*deletion.*protection.*is enabled
- •Disable deletion protection first: set lifecycle_rule or API flag
- •Update the resource to disable protection, apply, then destroy
Terraform each.key used without for_each
terraform.*Error:.*Invalid reference.*each\.key.*not in for_each
- •Add for_each argument to the resource or module block
- •Replace each.key with count.index if using count
Terraform import into occupied state address
terraform.*Error:.*cannot import.*state already contains
- •Remove existing resource from state: terraform state rm <address>
- •Use a different resource address for the import
Terraform S3 backend bucket doesn't exist
terraform.*Error:.*S3 bucket.*does not exist.*backend
- •Create the S3 bucket manually before terraform init
- •Check bucket name and region match backend configuration
Terraform state lock cannot be acquired
Error acquiring the state lock|Lock Info|lock.*already held
- •Wait for the other operation to complete
- •Force unlock if the lock is stale: terraform force-unlock LOCK_ID
Terraform provider not found or unavailable
provider.*not found|Could not retrieve the list of available versions for provider
- •Run terraform init to download required providers
- •Add required_providers block with source in terraform {} block
Resource already exists outside Terraform
resource.*already exists|Error creating.*already exists|409.*Conflict
- •Import the existing resource: terraform import resource.name id
- •Remove the resource from state if it shouldn't be managed: terraform state rm
Drift detected between state and reality
Plan.*differ.*actual.*drift|Objects have changed outside of Terraform
- •Run terraform plan to see what changed
- •Run terraform apply to reconcile state with config
Terraform module not found
Module not installed|Module.*not found|Could not download module
- •Run terraform init to download modules
- •Verify the module source path/URL is correct
Cloud provider credentials invalid or expired
Error.*validating provider credentials|NoCredentialProviders|ExpiredToken
- •Refresh credentials: aws sso login, az login, or gcloud auth login
- •Check AWS_PROFILE or environment variables are set correctly
Reference to undeclared Terraform object
Invalid reference|Reference to undeclared (resource|variable|module)
- •Declare the variable in variables.tf
- •Check for typos in the resource reference: module.name.output
Dependency cycle in Terraform resources
Cycle.*detected|dependency cycle
- •Break the cycle by using depends_on with a third intermediary resource
- •Use data source to reference one of the resources instead
Cannot destroy resource due to dependencies
Error.*deleting.*Cannot delete.*in use|DependencyViolation
- •Destroy dependent resources first by using target: terraform destroy -target=dependent
- •Remove the dependency relationship before destroying
Accessing non-existent resource attribute
Unsupported attribute|This object does not have an attribute named
- •Check provider documentation for available attributes
- •Verify you're using the correct resource type name
Type constraint error in variable or output
value of.*cty\..*is not suitable|Inappropriate value.*string required
- •Check the variable type constraint matches the value being passed
- •Use tostring(), tonumber(), tolist() for explicit conversion
Backend configuration changed, init required
Backend initialization required|Backend.*changed|rerun.*init
- •Run terraform init -reconfigure to reinitialize with new backend
- •Use terraform init -migrate-state to move state to new backend
Resource creation timed out
Error.*creating.*timeout|context deadline exceeded|operation.*timed out
- •Increase the timeout in resource timeouts block
- •Check cloud provider console for the resource status
Invalid count or for_each argument
Invalid count argument|count\.index.*invalid|for_each.*invalid
- •Ensure count value is a whole number, not a computed value that might be unknown
- •For for_each: use toset() to convert list to set
Terraform state file missing or empty
state.*is empty|No state file found|Failed to load state
- •Check backend configuration points to correct location
- •Restore from state backup if available (.terraform.tfstate.backup)
Provider inconsistency between plan and apply
Provider produced inconsistent result|planned.*but then.*applied
- •Upgrade the provider to latest version
- •Add ignore_changes lifecycle for the drifting attribute
Insufficient IAM permissions for Terraform operation
AccessDenied|UnauthorizedOperation|does not have.*permission
- •Add the required IAM policy to the Terraform execution role
- •Check the error for the specific action and resource ARN needed
Duplicate resource definition in configuration
Duplicate resource.*address|resource.*already managed
- •Remove the duplicate resource block
- •Use count or for_each for multiple similar resources
Saved plan is stale due to state changes
Saved plan is stale|plan.*outdated|state.*modified.*since.*plan
- •Regenerate the plan: terraform plan -out=newplan
- •Ensure no other process is modifying state concurrently
Provider plugin version incompatible or missing
Failed to instantiate provider|plugin.*not found|incompatible.*provider
- •Run terraform init -upgrade to download compatible provider version
- •Pin provider version in required_providers: version = "~> 4.0"