github.com/hugorut/terraform@v1.1.3/website/docs/cli/commands/fmt.mdx (about)

     1  ---
     2  page_title: 'Command: fmt'
     3  description: >-
     4    The terraform fmt command rewrites configuration files to a canonical format
     5    and style.
     6  ---
     7  
     8  # Command: fmt
     9  
    10  The `terraform fmt` command is used to rewrite Terraform configuration files
    11  to a canonical format and style. This command applies a subset of
    12  the [Terraform language style conventions](/language/syntax/style),
    13  along with other minor adjustments for readability.
    14  
    15  Other Terraform commands that generate Terraform configuration will produce
    16  configuration files that conform to the style imposed by `terraform fmt`, so
    17  using this style in your own files will ensure consistency.
    18  
    19  The canonical format may change in minor ways between Terraform versions, so
    20  after upgrading Terraform we recommend to proactively run `terraform fmt`
    21  on your modules along with any other changes you are making to adopt the new
    22  version.
    23  
    24  We don't consider new formatting rules in `terraform fmt` to be a breaking
    25  change in new versions of Terraform, but we do aim to minimize changes for
    26  configurations that are already following the style examples shown in the
    27  Terraform documentation. When adding new formatting rules, they will usually
    28  aim to apply more of the rules already shown in the configuration examples
    29  in the documentation, and so we recommend following the documented style even
    30  for decisions that `terraform fmt` doesn't yet apply automatically.
    31  
    32  Formatting decisions are always subjective and so you might disagree with the
    33  decisions that `terraform fmt` makes. This command is intentionally opinionated
    34  and has no customization options because its primary goal is to encourage
    35  consistency of style between different Terraform codebases, even though the
    36  chosen style can never be everyone's favorite.
    37  
    38  We recommend that you follow the style conventions applied by `terraform fmt`
    39  when writing Terraform modules, but if you find the results particularly
    40  objectionable then you may choose not to use this command, and possibly choose
    41  to use a third-party formatting tool instead. If you choose to use a
    42  third-party tool then you should also run it on files that are generated
    43  automatically by Terraform, to get consistency between your hand-written files
    44  and the generated files.
    45  
    46  ## Usage
    47  
    48  Usage: `terraform fmt [options] [DIR]`
    49  
    50  By default, `fmt` scans the current directory for configuration files. If
    51  the `dir` argument is provided then it will scan that given directory
    52  instead. If `dir` is a single dash (`-`) then `fmt` will read from standard
    53  input (STDIN).
    54  
    55  The command-line flags are all optional. The list of available flags are:
    56  
    57  * `-list=false` - Don't list the files containing formatting inconsistencies.
    58  * `-write=false` - Don't overwrite the input files. (This is implied by `-check` or when the input is STDIN.)
    59  * `-diff` - Display diffs of formatting changes
    60  * `-check` - Check if the input is formatted. Exit status will be 0 if
    61    all input is properly formatted and non-zero otherwise.
    62  * `-recursive` - Also process files in subdirectories. By default, only the given directory (or current directory) is processed.