Skip to main content
After applying Terraform configurations to create infrastructure, you’ll eventually need to remove resources. This guide explains terraform destroy — the Terraform command that deletes Terraform-managed infrastructure from your current working directory (or workspace). Terraform destroy terminates resources tracked in your current state and shows a destruction plan before making changes. Use it to clean up environments you no longer need.

Overview

  • terraform destroy removes all Terraform-managed resources in the active workspace by default.
  • You can also remove resources by editing configuration files (deleting resource blocks) and running terraform apply, which will detect and destroy resources that no longer appear in the configuration.
  • Targeted destruction (-target) lets you destroy specific resources but is an advanced operation and can lead to unexpected results if configuration files are not updated accordingly.

Ways to remove resources

Full-destroy (default)

Run this to remove everything Terraform manages in the current workspace:
Terraform displays a destruction plan and asks for confirmation. Type yes to proceed. Delete the resource blocks from your .tf files, then run:
Terraform will show a plan that includes destroying the resources that were removed from the configuration, then apply those changes after you confirm.

State file behavior

When Terraform destroys resources (either via terraform destroy or by removing blocks and applying), it also removes those entries from the state file. Once removed, Terraform no longer tracks those resources. This behavior ensures the state accurately reflects the resources currently managed. If a resource remains defined in the configuration but is absent from the state, Terraform will attempt to recreate it on the next terraform apply.
Destroy operations are effectively irreversible from Terraform’s perspective. There is no built-in “undo” or recycle bin. Some cloud providers may offer snapshots or backups, but those recovery paths are outside Terraform. Always review the destruction plan carefully before typing yes, and avoid running destroy accidentally in production.
A purple warning slide showing an alarm icon and the message that destroy operations are irreversible and to always review the plan carefully. Diagonal black-and-yellow hazard stripes run across the right side.

How destroy respects dependencies

Terraform destroys resources while respecting the dependency graph in reverse order of creation. This prevents errors such as deleting a network before deleting VMs that depend on it. Example ordering for a network topology:
  • VMs (depend on subnets) are destroyed first.
  • Subnets (depend on network) are destroyed next.
  • Network is destroyed last.
Terraform computes this ordering automatically, so you do not need to manually sequence deletions for dependent resources when using terraform destroy or a config-driven terraform apply.

Targeted destroy

To destroy a specific resource (or set of resources), use the -target flag:
Example:
This command will destroy only aws_instance.web_one and leave other managed resources intact.
Tip: If you want to preview changes before destroying a specific resource, run terraform plan -destroy -target=... to see the destruction plan without applying it.

Caution about targeted destroys

Using -target is an advanced operation. If you destroy a resource with -target but leave its block in your configuration, the next terraform apply will attempt to recreate it because it still exists in code but not in state. Example sequence that will recreate a resource if its configuration remains:
If your intent is to permanently remove a resource, delete the corresponding resource block from your configuration before running terraform apply.

Best practices

  • Prefer removing resource blocks and running terraform apply for selective deletions—this keeps configuration and state aligned.
  • Use workspaces to separate environments (dev/stage/prod) to reduce risk of accidental destruction.
  • Avoid terraform destroy in production unless you are certain; consider automated safeguards or manual approvals.
  • Use terraform plan -destroy to preview what will be removed.
  • Never run terraform destroy with -auto-approve in production without a prior review.

Quick summary

  • terraform destroy removes Terraform-managed resources and prompts for confirmation after showing a destruction plan.
  • Removing resource blocks and running terraform apply is the recommended way to selectively delete resources.
  • Destroy operations also remove entries from the state file.
  • Destruction is irreversible via Terraform; always inspect the plan.
  • Use -target only when necessary and remove config blocks if you don’t want resources recreated.

Watch Video