HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 61 of 223

Terraform Associate 004. Associate level, HashiCorp. Free question with the correct answer and a full explanation.

HashiCorp Terraform Associate (004) Question 61

Single answer3c Validate a Terraform configuration

A 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?

  1. A

    terraform validate

  2. B

    terraform plan

  3. C

    terraform fmt -check

  4. 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 validate checks 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 after terraform init, and it does not create an execution plan or apply infrastructure changes.

  • B. Incorrect.

    Incorrect. terraform plan performs a planning operation, which is more than validation. It compares configuration against state and may require access to providers and backend information. While plan can 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 -check verifies 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 test is 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.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam