Skip to content
👷 The Terragrunt website redesign is Work In Progress! 👷
For a list of outstanding TODOs see this.
To give feedback, click here.

fmt

Usage

Recursively find HashiCorp Configuration Language (HCL) files and rewrite them into a canonical format.

Examples

Recursively format all HCL files in the current directory.

Terminal window
terragrunt hcl fmt

Flags

--check

Enable check mode in the hclfmt command.

When enabled, Terragrunt will check if HCL files are properly formatted without making any changes. This is useful in CI/CD pipelines to ensure consistent formatting.

The command will:

  • Exit with status code 0 if files are properly formatted
  • Exit with status code 1 if any files need formatting

Example:

Terminal window
terragrunt hcl fmt --check
Type: bool

Environment Variables:

  • TG_HCLFMT_CHECK

--diff

Print diff between original and modified file versions when running with 'hclfmt'.

When enabled, Terragrunt will show the differences between the original and formatted versions of HCL files. This helps you understand what changes the formatter would make.

Example:

Terminal window
terragrunt hcl fmt --diff
Type: bool

Environment Variables:

  • TG_HCLFMT_DIFF

--exclude-dir

Skip HCL formatting in given directories.

Specifies directories to exclude from HCL formatting. This is useful when you want to skip formatting certain parts of your codebase.

Example:

Terminal window
terragrunt hcl fmt --exclude-dir=vendor --exclude-dir=.terragrunt-cache
Type: string

Environment Variables:

  • TG_HCLFMT_EXCLUDE_DIR

--file

The path to a single hcl file that the hclfmt command should run on.

Specifies a single HCL file to format instead of recursively searching for files. This is useful when you want to format just one specific file.

Example:

Terminal window
terragrunt hcl fmt --file=./environments/prod/terragrunt.hcl
Type: string

Environment Variables:

  • TG_HCLFMT_FILE

--stdin

Format HCL from stdin and print result to stdout.

When enabled, Terragrunt will read HCL content from standard input, format it, and write the result to standard output. This is useful for integrating with text editors or other tools.

Example:

Terminal window
echo 'locals { foo="bar" }' | terragrunt hcl fmt --stdin
Type: bool

Environment Variables:

  • TG_HCLFMT_STDIN