Course contentsShow
← Cloud and Infrastructure
Lesson 780 of 2,98914. Terraform FundamentalsFree lesson

terraform destroy Workflow

Safely destroying all resources managed by Terraform and understanding the destruction order.

terraform destroy Workflow

What you'll learn: How to safely tear down all infrastructure managed by Terraform, understanding the destruction order and confirmation steps.

What is terraform destroy?

The terraform destroy command is Terraform's built-in way to delete all resources defined in your configuration. Think of it as the "undo" button for your entire infrastructure—it systematically dismantles everything Terraform created, leaving no orphaned resources behind.

How It Works

When you run terraform destroy, Terraform:

  1. Reads your configuration and state file to identify what needs removal
  2. Creates a destruction plan showing exactly what will be deleted
  3. Determines the correct order for deletion based on dependencies (reverse of creation order)
  4. Prompts for confirmation before proceeding
  5. Deletes resources one by one, respecting dependency chains

The Order Matters

Just as you can't demolish a building's foundation before removing the roof, Terraform destroys resources in reverse dependency order. If Resource B depends on Resource A, Terraform destroys B first, then A. This prevents errors from trying to delete something another resource still needs.

The Workflow

terraform destroy

Terraform shows you a destruction plan (similar to terraform plan, but for deletions), then asks:

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure...
  Enter a value: 

Type yes to proceed. You can skip the prompt with:

terraform destroy -auto-approve

⚠️ Use -auto-approve with extreme caution—there's no undo button for destruction!

Key Takeaway: terraform destroy safely removes all managed infrastructure by analyzing dependencies and destroying resources in reverse order, always requiring explicit confirmation unless overridden.