Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 35


You have multiple team members collaborating on infrastructure as code (IaC) using Terraform, and want to apply formatting standards for readability.

How can you format Terraform HCL (HashiCorp Configuration Language) code according to standard Terraform style convention?

Show Answer
Correct Answer: A

To format Terraform HCL code according to standard Terraform style convention, the most efficient method is to run the 'terraform fmt' command. This command automatically formats Terraform configuration files to ensure they adhere to the style conventions, such as correct indentation and alignment of equal signs. This approach ensures consistency and saves time compared to manual formatting or custom scripts.

Discussion

17 comments
Sign in to comment
vitasacOption: A
Apr 29, 2022

Yes Answer A

calebvarOption: A
Apr 25, 2022

correct answer is A

campsOption: A
Mar 31, 2023

A. Run the terraform fmt command during the code linting phase of your CI/CD process. Terraform provides a command called terraform fmt that can be used to automatically format Terraform HCL code according to the standard Terraform style convention. Running this command on your codebase during the code linting phase of your CI/CD process can ensure that your code is formatted consistently across your team and conforms to the standard Terraform style convention.

AwadhOption: A
Jul 9, 2023

A is the correct answer, who is writing the answers

Shane_COption: A
Jul 4, 2023

Now they have to be joking. The only reasonable answer is A. Everything else is just nonsense

nickyop
Mar 9, 2024

Yes, thank you!

ghostGuiggsOption: A
Nov 2, 2023

A is the answer

nickyopOption: A
Mar 9, 2024

Okay, as obvious as the option A is the correct answer, here's one question. What happens if such questions arise in the terraform exam where they have the wrong answers saved as the right ones? For example, in the above question, if we choose the most voted option in the exam, we'll lose 1 mark just because the right answer is C according to the system?? And FYI, I have already undergone one attempt for the exam which I was certain that I would pass because it went pretty well but I failed by 2%. And I know for sure it is only because of such contradictory questions! @Hashicorp please settle such questions once and for all!

AkaAka4
Apr 23, 2024

Why are you even tagging Hashicorp here... do you think they will see your comment😂

alexsandroeOption: A
Feb 25, 2023

FMT helped de code

hasanuckunOption: A
Mar 16, 2023

answer is a

Power123Option: A
Mar 30, 2023

A is correct

connecttozeeOption: A
Apr 4, 2023

A is correct

Bluemoon22Option: A
Apr 24, 2023

A, by using terraform fmt command

Ni33Option: A
May 1, 2023

A is the correct answer

Ni33Option: A
May 8, 2023

A is correct

vc1011Option: A
Jul 16, 2023

ITs very evident A

gofavad926Option: A
Sep 28, 2023

A for sure

Tyler2023Option: C
Oct 21, 2023

The answer C is correct You can manually format your TF configuration to follow the Style Conventions Option A doesn't make any sense, why you run the terraform fmt in CI/CI process? that will only format the copy of the configuration in the remote agent that is running your configuration files, it doesn't modify your source codes in version control system. Option C followed the Terraform style convention, but it only do it manually https://developer.hashicorp.com/terraform/language/syntax/style

Clapton79
Nov 9, 2023

Pull Request is a CI/CD process and it can format code and it does modify your version control.

nickyop
Mar 9, 2024

Referring the link you have shared, I think you missed a note where they have mentioned "You can enforce these conventions automatically by running terraform fmt."