Skip to content
Latchkey

terraform destroy: Usage, Options & Common CI Errors

Tear down everything Terraform manages - carefully.

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 creates 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 usage

Terminal
# Destroy everything in this state (prompts for yes)
terraform destroy

# Non-interactive teardown (ephemeral PR env cleanup)
terraform destroy -auto-approve -var-file=preview.tfvars

# Destroy only one resource (equivalent to terraform apply -destroy -target=...)
terraform destroy -target=aws_instance.web

Common error in CI: dependency violation on delete

Teardown often fails with "Error: deleting ... : DependencyViolation: resource ... has a dependent object" - for example a VPC that still has a manually-attached ENI, or an S3 bucket that is not empty. Fix: remove the external dependent first (empty the bucket, detach the ENI), or set force_destroy = true on resources that support it (e.g. aws_s3_bucket). Re-run destroy; Terraform retries the dependency chain.

Key options

OptionPurpose
-auto-approveSkip the destroy confirmation
-target=ADDRDestroy only specific resources
-var-file=FILEVariables for the destroy plan
-input=falseNever prompt (required in CI)

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →