HashiCorp Terraform Associate (004) Question 61
Single answer3c Validate a Terraform configurationA platform engineer is reviewing a teammate's Terraform changes before merging them. The team wants a fast check in CI that can catch configuration mistakes such as invalid references, missing required arguments, and malformed module blocks without contacting any remote provider APIs or creating an execution plan. Which command should the engineer use?
- A
terraform validate
- B
terraform plan
- C
terraform fmt -check
- D
terraform test
Show answer and explanation
Correct answer: A
Explanation
The best choice is terraform validate. In Terraform workflows, validate is designed to check whether configuration files are syntactically valid and internally consistent. This includes catching many common authoring mistakes before running terraform plan or terraform apply. A typical CI sequence is terraform init -backend=false followed by terraform validate, especially when the goal is fast feedback without interacting with remote backends or producing a plan. By contrast, terraform fmt -check only checks formatting, and terraform plan is a more expensive operation that evaluates proposed infrastructure changes. HashiCorp documentation describes terraform validate as the command for validating configuration files in a directory.
- A. Correct.
Correct.
terraform validatechecks whether the configuration is syntactically valid and internally consistent. It can detect issues such as invalid resource references, unsupported arguments, incorrect module block structure, and missing required arguments. It is commonly used in CI as a quick validation step afterterraform init, and it does not create an execution plan or apply infrastructure changes. - B. Incorrect.
Incorrect.
terraform planperforms a planning operation, which is more than validation. It compares configuration against state and may require access to providers and backend information. Whileplancan reveal many errors, it is not the best answer because the scenario specifically asks for a fast validation step that does not create an execution plan. - C. Incorrect.
Incorrect.
terraform fmt -checkverifies whether configuration files conform to Terraform's canonical formatting style. This is useful for code quality and consistency, but it does not validate references, required arguments, or module configuration correctness. - D. Incorrect.
Incorrect.
terraform testis used for executing Terraform tests defined in test files, not for basic configuration validation in the way described here. It is intended for testing module behavior and assertions, not as the primary command for quickly checking general configuration validity before planning.