github.com/hashicorp/packer@v1.14.3/website/content/docs/commands/fmt.mdx (about)

     1  ---
     2  description: |
     3    The `packer fmt` Packer command formats HCL2 configuration files to a canonical format and style to help you prevent coding errors.
     4  page_title: packer fmt command reference
     5  ---
     6  
     7  # `packer fmt` command reference
     8  
     9  The `packer fmt` Packer command is used to format HCL2 configuration files to
    10  a canonical format and style. JSON files (.json) are not modified. This command
    11  applies a subset of HCL language style conventions, along with other minor
    12  adjustments for readability.
    13  
    14  `packer fmt` will display the name of the configuration file(s) that need formatting,
    15  and write any formatted changes back to the original configuration file(s).
    16  
    17  Example usage:
    18  
    19  Check if configuration file(s) need to be formatted, but don't write the changes.
    20  
    21  ```shell-session
    22  $ packer fmt -check .
    23  my-template.pkr.hcl
    24  
    25  ```
    26  
    27  Format a configuration file, writing the changes back to the original file.
    28  
    29  ```shell-session
    30  $ packer fmt my-template.pkr.hcl
    31  my-template.pkr.hcl
    32  
    33  ```
    34  
    35  Format multiple configuration files, writing the changes back to respective original files.
    36  
    37  ```shell-session
    38  $ packer fmt my-template.pkr.hcl my-varfile.pkrvars.hcl
    39  my-template.pkr.hcl
    40  my-varfile.pkrvars.hcl
    41  
    42  ```
    43  
    44  Format a configuration file, reading from stdin and writing to stdout.
    45  
    46  ```shell-session
    47  $ packer fmt -
    48  
    49  // You can use pipes to combine this feature with other command line options
    50  $ cat my-template.pkr.hcl | packer fmt -
    51  ```
    52  
    53  ## Options
    54  
    55  - `-check` - Checks if the input is formatted. Exit status will be 0 if all
    56    input is properly formatted and non-zero otherwise.
    57  
    58  - `-diff` - Display diffs of any formatting change
    59  
    60  - `-write=false` - Don't write formatting changes to source files
    61    (always disabled if using -check)
    62  
    63  - `-` - read formatting changes from stdin and write them to stdout.
    64  
    65  - `-recursive` Also process files in subdirectories. By default, only the
    66    given directory (or current directory) is processed.