mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-26 00:31:18 -04:00
71 lines
2.4 KiB
Text
71 lines
2.4 KiB
Text
---
|
|
description: |
|
|
The `packer fmt` Packer command formats HCL2 configuration files to a canonical format and style to help you prevent coding errors.
|
|
page_title: packer fmt command reference
|
|
---
|
|
|
|
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
> [!IMPORTANT]
|
|
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
|
|
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
|
|
# `packer fmt` command reference
|
|
|
|
The `packer fmt` Packer command is used to format HCL2 configuration files to
|
|
a canonical format and style. JSON files (.json) are not modified. This command
|
|
applies a subset of HCL language style conventions, along with other minor
|
|
adjustments for readability.
|
|
|
|
`packer fmt` will display the name of the configuration file(s) that need formatting,
|
|
and write any formatted changes back to the original configuration file(s).
|
|
|
|
Example usage:
|
|
|
|
Check if configuration file(s) need to be formatted, but don't write the changes.
|
|
|
|
```shell-session
|
|
$ packer fmt -check .
|
|
my-template.pkr.hcl
|
|
|
|
```
|
|
|
|
Format a configuration file, writing the changes back to the original file.
|
|
|
|
```shell-session
|
|
$ packer fmt my-template.pkr.hcl
|
|
my-template.pkr.hcl
|
|
|
|
```
|
|
|
|
Format multiple configuration files, writing the changes back to respective original files.
|
|
|
|
```shell-session
|
|
$ packer fmt my-template.pkr.hcl my-varfile.pkrvars.hcl
|
|
my-template.pkr.hcl
|
|
my-varfile.pkrvars.hcl
|
|
|
|
```
|
|
|
|
Format a configuration file, reading from stdin and writing to stdout.
|
|
|
|
```shell-session
|
|
$ packer fmt -
|
|
|
|
// You can use pipes to combine this feature with other command line options
|
|
$ cat my-template.pkr.hcl | packer fmt -
|
|
```
|
|
|
|
## Options
|
|
|
|
- `-check` - Checks if the input is formatted. Exit status will be 0 if all
|
|
input is properly formatted and non-zero otherwise.
|
|
|
|
- `-diff` - Display diffs of any formatting change
|
|
|
|
- `-write=false` - Don't write formatting changes to source files
|
|
(always disabled if using -check)
|
|
|
|
- `-` - read formatting changes from stdin and write them to stdout.
|
|
|
|
- `-recursive` Also process files in subdirectories. By default, only the
|
|
given directory (or current directory) is processed.
|