CertLumen

HashiCorp Terraform Associate (004) · Section 3 · 12% of the exam

Destroy Terraform-managed infrastructure

One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Core Terraform workflow”. Here is what it covers, the points to remember and a question to try.

What it covers

terraform destroy removes everything a configuration manages and is simply apply in destroy mode, so you can preview it with a plan. terraform fmt rewrites files to the canonical style. This lesson covers destroy options and safeguards, fmt options and exit codes, and the HashiCorp style conventions.

Points to remember

  • terraform destroy equals terraform apply -destroy; it takes no plan file argument.
  • Preview a destroy with terraform plan -destroy; save it with -out and run it with terraform apply FILE.
  • Destroy works in reverse dependency order and only touches objects in this state.
  • lifecycle { prevent_destroy = true } makes any destroy plan for that resource fail.
  • Deleting a resource block and applying destroys it; a removed block with destroy = false only drops it from state.

Try a question

Which command is a shortcut for terraform apply -destroy?

  1. Aterraform destroy
  2. Bterraform plan -destroy
  3. Cterraform init -destroy
  4. Dterraform fmt -destroy
Show the answer

A. terraform destroy runs in destroy mode, shows the plan and asks for confirmation. To preview, use terraform plan -destroy.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Destroy and formatting teaches this objective (about 30 minutes), and 10 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 37 objectives · Next objective →