🎓 A1Learner
🔍
0 of 50 lessons completed

terraform apply and terraform destroy

Terraform apply makes a configuration real, and terraform destroy takes it down again. Apply builds, destroy removes.

Apply makes it real

Apply creates the resources in the plan. The output lists how many were added.

terraform apply

Skip the confirmation

The auto-approve flag skips the prompt. Use it only in scripts, never by habit.

terraform apply -auto-approve

Destroy takes it down

Destroy lists what it will remove and asks for confirmation. Answer yes to remove it all.

terraform destroy

Example

# main.tf
terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "2.9.1"
    }
  }
}

resource "local_file" "hello" {
  filename = "hello.txt"
  content  = "Hello from Terraform."
}

# Commands:
# terraform init
# terraform plan
# terraform apply
# terraform destroy

Key points

  • Apply carries out the plan and creates or changes resources.
  • Apply asks for confirmation before it changes anything.
  • Destroy removes every resource the configuration manages.
  • Destroy also asks for confirmation, because removal cannot be undone.
  • Destroy after practice, so a practice resource does not linger.
  • A destroyed resource can be built again by running apply.

Apply creates the file and reports one added resource. Destroy then removes it and reports one destroyed resource. Practice ends clean, with nothing left behind.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does terraform destroy do?