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.tfvarsIn 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
terraform apply Command ReferenceReference for terraform apply in CI/CD: apply a saved plan non-interactively, use -auto-approve, and cap para…
terraform workspace Command ReferenceReference for terraform workspace in CI/CD: create, select, and list named workspaces for per-environment or…
terraform state list Command ReferenceReference for terraform state list in CI/CD: enumerate and filter the resource addresses Terraform tracks, th…