nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-003 · 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…

The correct answer is A. Run the terraform fmt command during the code linting phase of your CI/CD process Most Voted. The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability. Running this command on your configuration…

Use the core Terraform workflow

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 Most Voted
  • 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

(60 responses)
  • A
    80% (48)
  • B
    12% (7)
  • C
    7% (4)
  • D
    2% (1)

Explanation

The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability. Running this command on your configuration files before committing them to source control can help ensure consistency of style between different Terraform codebases, and can also make diffs easier to read. You can also use the -check and - diff options to check if the files are formatted and display the formatting changes respectively. Running the terraform fmt command during the code linting phase of your CI/CD process can help automate this process and enforce the formatting standards for your team.

Topics

#terraform fmt#HCL formatting#code style#CI/CD

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-003 Practice