nerdexam
HashiCorp

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

Read, generate, and modify configuration

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)
  • A
    2% (1)
  • B
    4% (2)
  • C
    91% (49)
  • D
    4% (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

#HCL formatting#Code style#Readability#Configuration standards

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice