opentofu/website/docs/commands/fmt.html.markdown
Martin Atkins 04f3766fd9 website: Indicate v0.12-only content
We have released the v0.12-oriented content to the website early in order
to support the beta process, but in some places we neglected to explicitly
mark features or content as being v0.12-only.

Here we add explicit markers to the main cases we've seen where readers
have reported confusion, along with some other tweaks in similar vein.
2019-03-18 12:42:21 -07:00

1.7 KiB

layout page_title sidebar_current description
docs Command: fmt docs-commands-fmt The `terraform fmt` command is used to rewrite Terraform configuration files to a canonical format and style.

Command: fmt

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.

Other Terraform commands that generate Terraform configuration will produce configuration files that conform to the style imposed by terraform fmt, so using this style in your own files will ensure consistency.

The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform we recommend to proactively run terraform fmt on your modules along with any other changes you are making to adopt the new version.

Usage

Usage: terraform fmt [options] [DIR]

By default, fmt scans the current directory for configuration files. If the dir argument is provided then it will scan that given directory instead. If dir is a single dash (-) then fmt will read from standard input (STDIN).

The command-line flags are all optional. The list of available flags are:

  • -list=true - List files whose formatting differs (disabled if using STDIN)
  • -write=true - Write result to source file instead of STDOUT (disabled if using STDIN or -check)
  • -diff=false - Display diffs of formatting changes
  • -check=false - Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.