Skip to content
Latchkey

terraform destroy Command Reference

Tear down everything Terraform manages in this state.

terraform destroy removes all resources tracked in state. It is the inverse of apply and is most useful for ephemeral environments and PR preview stacks.

What it does

terraform destroy builds a plan that deletes every resource in the current state, then executes it after approval. It respects dependency order, destroying dependents before their dependencies.

Common flags and usage

  • -auto-approve: skip the destroy confirmation
  • -target=ADDR: destroy only specific resources
  • -var-file=FILE: variables for the destroy plan
  • -input=false: never prompt (required in CI)

Example

shell
# Tear down a per-PR preview environment on PR close
- name: Destroy preview env
  run: terraform destroy -input=false -auto-approve -var-file=preview.tfvars

In CI

Drive destroy from a PR-close or scheduled-cleanup job with -auto-approve and a per-environment var file or workspace. Resources with dependent objects created outside Terraform may need force_destroy=true (for example aws_s3_bucket) before teardown succeeds.

Key takeaways

  • destroy deletes every resource in the current state in dependency order.
  • Use -auto-approve and a per-env var file for unattended preview-stack cleanup.
  • External dependents can block deletion; force_destroy helps where supported.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →