CertLumen

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

Apply formatting and style adjustments to a configuration

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

By default, which files does terraform fmt process when run without a target?

  1. AAll Terraform files in the current directory and every subdirectory beneath it
  2. BOnly the files changed in the last Git commit of the repository
  3. CThe Terraform files in the current directory only, not subdirectories
  4. DOnly the files listed in .terraform.lock.hcl
Show the answer

C. By default fmt scans the current directory. A directory, a file or - for standard input can be given as a target.

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 →