Interview Prep/Terraform/Plan Errors and Unexpected Replacements

`Error: Instance cannot be destroyed` — `Resource aws_s3_bucket.state has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed.`

BeginnerTroubleshootingPlan Errors and Unexpected Replacements
Answer

Likely causes → The guard is working: your change causes a destroy or replace (rename, for_each key change, a forcing argument).

Diagnose → Find what triggers the destroy in the plan.

Fix → Fix the code (add moved, revert the forcing change). Only remove prevent_destroy if destroying is truly intended and approved.

Prevent → Keep prevent_destroy on state buckets, databases, KMS keys and DNS zones.

All Terraform questions

More on Plan Errors and Unexpected Replacements