HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 63 of 223

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

HashiCorp Terraform Associate (004) Question 63

Single answer3c Validate a Terraform configuration

A platform engineer updates a Terraform root module before opening a pull request. They want a fast check that the configuration is syntactically valid and internally consistent, without contacting the remote backend, refreshing state, or proposing infrastructure changes. Which command should they run from the root module directory after initializing the working directory?

  1. A

    terraform validate

  2. B

    terraform plan

  3. C

    terraform fmt -check

  4. D

    terraform apply -refresh-only

Show answer and explanation

Correct answer: A

Explanation

The best answer is terraform validate. In Terraform workflows, terraform validate is the command designed to confirm that configuration files are syntactically valid and internally consistent after the directory has been initialized with terraform init. This aligns with the scenario's goal: a quick pre-PR quality check that does not generate an execution plan or attempt to change infrastructure. By contrast, terraform plan is for previewing changes, terraform fmt -check only enforces canonical formatting, and terraform apply -refresh-only is a state/infrastructure operation rather than a validation step. HashiCorp documentation describes terraform validate as validating configuration files in a directory and recommends initialization first so required plugins and module information are available.

  • A. Correct.

    Correct. terraform validate checks whether the configuration is syntactically valid and internally consistent for the currently selected working directory. It verifies things such as valid references, argument types where possible, and general configuration structure. It does not create a plan or propose changes, making it the appropriate fast validation step after initialization.

  • B. Incorrect.

    Incorrect. terraform plan does more than validation. It evaluates the configuration against the current state and provider schemas to generate an execution plan, which is beyond the requirement of a quick validation-only check. Depending on configuration, it may also involve backend/state operations and refresh behavior unless additional flags are used.

  • C. Incorrect.

    Incorrect. terraform fmt -check verifies formatting, not configuration validity. It is useful in CI to enforce style consistency, but a properly formatted configuration can still contain invalid references, missing required arguments, or other errors that terraform validate would catch.

  • D. Incorrect.

    Incorrect. terraform apply -refresh-only is used to update state to match real infrastructure without changing remote objects. It is not a validation command and is specifically intended to work with state and infrastructure, which conflicts with the scenario's requirement to avoid proposing or applying infrastructure-related changes.

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