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.
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)- A91% (29)
- B6% (2)
- D3% (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.
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.
terraform init initializes the working directory and downloads provider plugins and modules - it performs no formatting of configuration files.
terraform validate checks that configuration syntax and references are internally consistent and valid, but does not reformat files to match canonical style.
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
Community Discussion
No community discussion yet for this question.