TF-004 Understand Terraform basics Practice Question
In Terraform, which command is used to format configuration files according to the HCL canonical style?
⚠ Common exam trap
In Terraform, `terraform fmt` is for formatting HCL style, while `terraform validate` checks syntax and internal consistency. Candidates often confuse these two commands.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
terraform fmt
`terraform fmt` is the dedicated Terraform CLI command that rewrites configuration files to adhere to the HCL canonical style, ensuring consistent formatting (e.g., indentation, alignment of equals signs). It does not modify the logic or state of the configuration, only its visual layout.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
terraform plan
Why it's wrong here
terraform plan previews pending changes by comparing configuration with state; it does not alter file formatting. It is tempting because plan is a routine pre-deployment step, so it would be correct when the question asks which command shows what apply would change.
- ✓
terraform fmt
Why this is correct
terraform fmt rewrites configuration files into the canonical HCL style, fixing indentation, alignment and spacing. It satisfies the stem's formatting requirement directly, unlike validate or plan, which check syntax or execution without altering file layout.
- ✗
terraform init
Why it's wrong here
terraform init downloads providers and initialises the working directory's backend and modules; it leaves configuration text untouched. It is tempting because init is the first command run in any new working directory, so it would be correct when the question asks how to prepare a directory for use.
- ✗
terraform validate
Why it's wrong here
terraform validate checks syntax and internal consistency of configuration but does not rewrite it to canonical style. It is tempting because validation also concerns configuration correctness, so it would be correct when the question asks how to confirm a configuration is syntactically valid.
- ✗
terraform apply
Why it's wrong here
terraform apply executes the planned changes against real infrastructure; it never rewrites source files. It is tempting because apply is the command practitioners run most often, so it would be correct when the question asks which command provisions resources from a saved plan.
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 434 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.