nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-004 · Question #114

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 A. Run the terraform fmt command during the code linting phase of your CI/CD process. 'terraform fmt' is the built-in Terraform command that automatically reformats all .tf files in the current directory (and optionally subdirectories with -recursive) to the canonical HCL style: consistent indentation, aligned equal signs within blocks, and standardized spacing. R

Submitted by olafpl· Apr 18, 2026Use Terraform CLI

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 Terraform file
  • DWrite a shell script to transform Terraform files using tools such as AWK, Python, and sed

How the community answered

(30 responses)
  • A
    93% (28)
  • C
    3% (1)
  • D
    3% (1)

Explanation

'terraform fmt' is the built-in Terraform command that automatically reformats all .tf files in the current directory (and optionally subdirectories with -recursive) to the canonical HCL style: consistent indentation, aligned equal signs within blocks, and standardized spacing. Running it in CI/CD ensures every merged commit meets the style standard without relying on manual review or custom scripts. The other options are either error-prone manual processes or reinventions of functionality that Terraform already provides natively.

Topics

#terraform fmt#HCL formatting#Code standards#Terraform CLI

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-004 Practice