HashiCorp Certified: Terraform Associate — Question 189
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. Replace all tabs with spaces
- B. Terraform automatically formats configuration on terraform apply
- C. Run terraform validate prior to executing terraform plan or terraform apply
- D. Use terraform fmt
Correct answer: D
Explanation
The correct answer is D, as 'terraform fmt' is specifically designed to format Terraform code according to standard conventions. Option A, while it addresses formatting, does not provide a comprehensive solution. Option B is incorrect because 'terraform apply' does not format code; it applies changes. Option C, while helpful for validation, does not enforce code formatting.