Terraform · Infrastructure as code

How do you destroy infrastructure safely?

MediumdestroysafetylifecycleUpdated Oct 2026
Quiz this track

Short answer

terraform destroy removes all resources in the configuration. Plan the destroy first, protect critical resources with prevent_destroy, and remember that removing a block and destroying are different operations.

Destroy runs the same graph in reverse, deleting dependent resources before their dependencies. It is appropriate for ephemeral environments and teardown, but dangerous when pointed at production or when the state does not match what you think it manages.

sh
terraform plan -destroy -out=destroy.tfplan
terraform show destroy.tfplan
terraform apply destroy.tfplan
Save and inspect the destroy plan before applying it. The plan still needs the correct workspace and credentials.

Safety practices

  • Confirm account, region and workspace before running destroy
  • Use prevent_destroy on databases, buckets with data and DNS zones
  • Take backups or snapshots that outlive the destroy
  • Prefer destroying ephemeral environments through the same CI pipeline

Removing a resource block and running apply also destroys that resource. This is easy to miss during a refactor. If the intent is to stop managing an object but keep it, remove it from state with terraform state rm or a removed block instead of deleting the configuration.

Destroy is not a rollback. Recreating a resource from configuration does not restore data that was deleted with it.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between terraform destroy and removing a resource block?
  2. 2How do you stop managing a resource without deleting it?
  3. 3How does prevent_destroy behave during destroy?
  4. 4In what order are resources destroyed?

Say it in the interview

I destroy through a saved destroy plan after confirming account, region and workspace. Critical resources get prevent_destroy and independent backups, because destroy is not a rollback. I also distinguish between deleting a block, which destroys the resource, and removing it from state, which leaves it alive but unmanaged. Ephemeral environments should be torn down through the same pipeline that created them.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.