gotchaterraformMajorpending
Gotcha: Terraform plan shows no changes but apply fails
Viewed 0 times
plan-applydriftstaterefreshimportout-of-band
Error Messages
Problem
terraform plan shows 'No changes' or shows expected changes, but terraform apply fails with errors about resources that already exist or can't be modified.
Solution
Causes of plan/apply drift:
terraform refresh # Sync state with reality
# Or: terraform plan -refresh-only
terraform state list # See what Terraform thinks exists
terraform state show <resource> # Compare with real resource
terraform init -upgrade # Update provider
terraform import aws_instance.web i-1234567890
# Now Terraform knows about the existing resource
# Resource creation takes time, immediate read fails
# Usually fixed by re-running apply
# Plan runs with stale credentials
# Fix: refresh credentials before apply
# Two people running apply simultaneously
# Fix: use remote state with locking (S3 + DynamoDB)
# Some providers have known plan/apply drift issues
# Check provider GitHub issues
Prevention:
- Out-of-band changes (resources modified outside Terraform):
terraform refresh # Sync state with reality
# Or: terraform plan -refresh-only
- State file is stale:
terraform state list # See what Terraform thinks exists
terraform state show <resource> # Compare with real resource
- Provider caching:
terraform init -upgrade # Update provider
- Resource already exists (importing):
terraform import aws_instance.web i-1234567890
# Now Terraform knows about the existing resource
- Eventual consistency (cloud APIs):
# Resource creation takes time, immediate read fails
# Usually fixed by re-running apply
- Permission changes between plan and apply:
# Plan runs with stale credentials
# Fix: refresh credentials before apply
- Concurrent modifications:
# Two people running apply simultaneously
# Fix: use remote state with locking (S3 + DynamoDB)
- Provider bugs:
# Some providers have known plan/apply drift issues
# Check provider GitHub issues
Prevention:
- Always run plan immediately before apply
- Use remote state with locking
- Tag resources so you know what Terraform manages
- Never modify Terraform-managed resources manually
Revisions (0)
No revisions yet.