Terraform
terraform stacks fmt reference
Use the terraform stacks fmt
command to rewrite all deployment and component configuration files for a Stack to a canonical format.
Usage
$ terraform stacks <global-stacks-flags> fmt [target] <options>
Description
The terraform stacks fmt
command rewrites all Terraform Stacks configuration files to a canonical format. All configuration files (.tfstack.hcl
, .tfcomponent.hcl
, and .tfdeploy.hcl
) are updated.
By default, fmt scans the current directory for Terraform Stacks configuration files. If you provide a directory for the target argument, then fmt will scan that directory instead. If you provide a file, then fmt will process just that file. If you provide a single dash ("-"), then fmt will read from standard input (stdin).
The content must be in the Terraform language native syntax; JSON is not supported.
Command arguments
target
: The target file or directory to format.- This argument is optional.
- Data type: string (file path, directory path, or "-" for stdin).
- Default: current directory.
Options
-list=true
: Don't list files whose formatting differs.- Optional.
- Data type: boolean.
- Default: true.
- Always false if reading from stdin(-) and always true if using -check.
-write=true
: Don't write to source files.- Optional.
- Data type: boolean.
- Default: true.
- Always false if reading from stdin(-) or using -check.
-diff
: Display diffs of formatting changes.- Optional.
- Data type: boolean.
- Default: false.
-check
: Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.- Optional.
- Data type: boolean.
- Default: false.
-recursive
: Also process files in subdirectories. By default, only the given directory (or current directory) is processed.- Optional.
- Data type: boolean.
- Default: false.
Examples
The following command formats all configuration files in the current directory:
$ terraform stacks fmt
The following command formats all configuration files in a specific directory:
$ terraform stacks fmt ./my-stack
The following command formats a specific file:
$ terraform stacks fmt stack.tfstack.hcl
The following command checks if files are properly formatted without making changes:
$ terraform stacks fmt -check
The following command shows the formatting differences that would be applied:
$ terraform stacks fmt -diff
The following command formats files recursively in subdirectories:
$ terraform stacks fmt -recursive
Global flags
Refer to Global flags reference for information about flags you can use with all commands.