HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 83 of 223

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

HashiCorp Terraform Associate (004) Question 83

Single answer3g Apply formatting and style adjustments to a configuration

Your team stores Terraform configurations in Git and enforces a pre-commit check before merging. A teammate submits a change that adds new resources, but the pre-commit pipeline fails because the configuration does not match the team's required Terraform formatting style. The resources and arguments are valid, and you do not want to change the behavior of the infrastructure. What is the most appropriate action to make the configuration comply with Terraform's standard formatting expectations before committing the change?

  1. A

    Run terraform fmt in the working directory and commit the resulting formatting-only changes

  2. B

    Run terraform validate to automatically rewrite the configuration into canonical Terraform style

  3. C

    Run terraform plan so Terraform can detect formatting issues and update the files before apply

  4. D

    Manually reorder all blocks and arguments to match the order shown in the provider documentation

Show answer and explanation

Correct answer: A

Explanation

The best answer is to run terraform fmt. In Terraform workflows, formatting is handled separately from validation and planning. terraform fmt automatically updates configuration files to Terraform's canonical style, making code easier to read and consistent across contributors without changing infrastructure behavior. By contrast, terraform validate checks correctness, and terraform plan previews infrastructure changes. HashiCorp documentation identifies terraform fmt as the command used to rewrite Terraform configuration files to a standard format, and it is commonly integrated into CI/CD and pre-commit processes for team-based development.

  • A. Correct.

    Correct. terraform fmt rewrites Terraform configuration files into a canonical format without changing their behavior. It is the standard command used to apply formatting and style adjustments to .tf and related configuration files. This is commonly used in local workflows, CI pipelines, and pre-commit hooks to ensure consistent style across a team.

  • B. Incorrect.

    Incorrect. terraform validate checks whether the configuration is syntactically valid and internally consistent, but it does not rewrite files or apply formatting changes. A common misconception is that validation also fixes style issues, but formatting and validation are separate Terraform commands.

  • C. Incorrect.

    Incorrect. terraform plan compares the current state and configuration to propose infrastructure changes. It does not edit configuration files or enforce style formatting. Someone might choose this option because plan is often used before apply, but it is unrelated to rewriting source files for style compliance.

  • D. Incorrect.

    Incorrect. Manual reordering is unnecessary and error-prone. Terraform's standard formatting should be applied with terraform fmt, not by trying to imitate examples from documentation. In addition, provider documentation examples are not a canonical formatting enforcement mechanism, and argument order usually does not affect behavior.

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