HashiCorp Certified: Terraform Associate — Question 140
Multiple team members are collaborating on infrastructure using Terraform and want to format their Terraform code following standard Terraform-style convention. How could they automatically ensure the code satisfies conventions?
Answer options
- A. Run the terraform fmt command during the code linting phase of your CI/CD process
- B. Manually apply two spaces indentation and align equal sign "=" characters in every Terraform file (*.tf)
- C. Run the terraform validate command prior to executing terraform plan or terraform apply
Correct answer: A
Explanation
The correct answer is A because running the terraform fmt command automatically formats the code according to Terraform's style guidelines, making it easy to maintain consistency. Option B is incorrect as manual formatting is prone to errors and does not guarantee adherence to conventions. Option C, while useful for checking syntax and configuration, does not format the code.