Module 3: Core Terraform Workflow

Lesson 3.6: Destroying Infrastructure

Plain language

Command Effect
terraform plan -destroy Previews what would be destroyed, and changes nothing
terraform destroy Plans destruction of every managed resource, prompts, then destroys
terraform apply -destroy Same as terraform destroy. destroy is a convenience alias.
terraform destroy -target=ADDR Destroys one resource and anything that depends on it. Exceptional use only.

Under the hood

  • Destruction runs in reverse dependency order. Dependents go first.
  • Resources with lifecycle { prevent_destroy = true } cause the destroy plan to error (Module 4).
  • The preferred way to remove one resource permanently is to delete its block from the configuration and run apply. The plan shows - for it. This keeps code and reality in agreement, which -target doesn't.
  • Destroy only affects resources in state. Unmanaged objects are untouched.
  • To stop managing a resource without destroying it, use a removed block or terraform state rm (Module 6).