Q: "terraform plan" suddenly shows 6 production resources will be destroyed, although no Terraform code was changed. What would you check first?
Triage runbook when terraform plan unexpectedly proposes destroying production resources (subnets, databases, VMs) without code changes, handling provider upgrades, remote changes, and lockfile validation.
Want to master this scenario in a live sandbox? KodeKloud's HashiCorp Certified Terraform Associate (003) Interactive Labs covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: When terraform plan proposes destroying production resources without code edits, NEVER apply. The cause is either an unpinned provider update with breaking attribute schema changes, out-of-band manual edits in the Azure Portal, or state backend corruption.
Examine the Exact Forces Replacement Trigger
Inspect the plan output line by line looking for # forces replacement. Terraform explicitly denotes which attribute change forces resource recreation (~ versus -/+).
terraform plan -out=tfplan
terraform show -no-color tfplan | grep -B 2 -A 5 "forces replacement"
Check .terraform.lock.hcl & Provider Version Drift
Verify if the azurerm provider version upgraded unexpectedly. Often a new provider version introduces default attribute values or renames fields that cause existing resources to be recreated.
Audit Azure Activity Logs for Manual Portal Modifications
Check Azure Activity Log on the 6 target resources. If an engineer manually modified a subnet CIDR, SKU, or tag via Azure Portal, Terraform detects drift and attempts to restore the declared state by recreating the resource.
- Check the plan output for # forces replacement to identify the exact attribute causing destruction.
- Verify provider version pinning in .terraform.lock.hcl against unexpected azurerm provider upgrades.
- Inspect Azure Activity Log to see if someone made manual changes in the Azure Portal that caused drift.
- Protect production resources using lifecycle { prevent_destroy = true } blocks.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Executing Terraform applies without inspecting '# forces replacement' warnings in plan output Attributes that force resource replacement destroy and recreate critical infrastructure (databases, load balancers), inducing unannounced production outages.
- Omitting remote state locking mechanisms (DynamoDB or backend native locks) for shared state files Without state locking, concurrent CI/CD pipeline executions or team applies create race conditions that corrupt the state file.
- Structuring entire enterprise cloud footprints into a single monolithic Terraform root module Monolithic state files slow plan execution dramatically, increase blast radius during failed applies, and create severe pipeline locking contention.
- Failing to pin required_providers versions, causing breaking provider upgrades in CI pipelines Unpinned provider versions automatically download breaking major upgrades during CI runs, introducing unexpected schema validation failures.