TA-002-P · 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 Config
The correct answer is C. Manually apply two spaces indentation and align equal sign "=" characters in every. The correct approach is to run 'terraform fmt' (option A), which is Terraform's built-in command for automatically reformatting HCL files to canonical style - consistent indentation, aligned equals signs, and proper spacing. Integrating it into a CI/CD linting phase enforces the
Question
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?
Options
- ARun the terraform fmt command during the code linting phase of your CI/CD process
- BDesignate one person in each team to review and format everyone's code
- CManually apply two spaces indentation and align equal sign "=" characters in every
- DWrite a shell script to transform Terraform files using tools such as AWK, Python, and sed
How the community answered
(54 responses)- A2% (1)
- B4% (2)
- C91% (49)
- D4% (2)
Explanation
The correct approach is to run 'terraform fmt' (option A), which is Terraform's built-in command for automatically reformatting HCL files to canonical style - consistent indentation, aligned equals signs, and proper spacing. Integrating it into a CI/CD linting phase enforces the standard automatically across the team. The provided answer key selects C (manual formatting), but manual work is error-prone and is precisely what 'terraform fmt' eliminates. Option A is correct.
Topics
Community Discussion
No community discussion yet for this question.