nerdexam
HashiCorp

TA-002-P · Question #162

The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform it is recommended to proactively run.

The correct answer is A. terraform fmt. terraform fmt rewrites Terraform configuration files to the canonical format and should be run proactively after upgrading Terraform since formatting conventions can change between versions.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform it is recommended to proactively run.

Options

  • Aterraform fmt
  • Bterraform init
  • Cterraform validate
  • Dterraform plan

How the community answered

(32 responses)
  • A
    91% (29)
  • B
    6% (2)
  • D
    3% (1)

Why each option

terraform fmt rewrites Terraform configuration files to the canonical format and should be run proactively after upgrading Terraform since formatting conventions can change between versions.

Aterraform fmtCorrect

The terraform fmt command scans .tf files in the current directory and rewrites them to match Terraform's current canonical style, including indentation, spacing, and argument alignment. Because the canonical format can shift slightly between minor Terraform versions, HashiCorp recommends running terraform fmt after each upgrade to keep configuration files consistent with the installed version's style rules.

Bterraform init

terraform init initializes the working directory and downloads provider plugins and modules - it performs no formatting of configuration files.

Cterraform validate

terraform validate checks that configuration syntax and references are internally consistent and valid, but does not reformat files to match canonical style.

Dterraform plan

terraform plan generates an execution plan showing proposed infrastructure changes and does not read or modify the formatting of configuration files.

Concept tested: Terraform fmt canonical formatting after version upgrade

Source: https://developer.hashicorp.com/terraform/cli/commands/fmt

Topics

#terraform fmt#CLI commands#Configuration formatting#Terraform upgrades

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice