Skip to content

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_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_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_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_FILE

--filter

Filter configurations using a flexible query language

The --filter flag provides a path-based querying syntax for targeting specific HCL files to format.

Usage

Terminal window
terragrunt hcl fmt --filter './prod/**'

Path-Based Filtering

Match HCL files by their file system path:

Terminal window
# Relative paths with globs
terragrunt hcl fmt --filter './envs/prod/**'
# Format all HCL files in a specific directory
terragrunt hcl fmt --filter './modules/**/*.hcl'
# Absolute paths
terragrunt hcl fmt --filter '/absolute/path/to/envs/dev/apps/*'

Negation

Exclude paths using the ! prefix:

Terminal window
# Exclude by path
terragrunt hcl fmt --filter '!./prod/**'
# Exclude specific directories
terragrunt hcl fmt --filter '!./test/**'

Intersection (Refinement)

Use the | operator to refine results:

Terminal window
# Format HCL files in prod directory, excluding tests
terragrunt hcl fmt --filter './prod/** | !./prod/test/**'
# Format specific file patterns
terragrunt hcl fmt --filter './**/*.hcl | !./**/test/**'

Union (Multiple Filters)

Specify multiple --filter flags to combine results using OR logic:

Terminal window
# Format files in either dev or staging directories
terragrunt hcl fmt --filter './dev/**' --filter './staging/**'

For comprehensive examples and advanced usage patterns, see the Filters feature documentation.

Type: list(string)

--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_STDIN

--parallelism

Parallelism for --all commands.

Sets the maximum number of concurrent operations when running commands with --all. This helps control resource usage and API rate limits when working with multiple units.

Type: integer

Environment Variables:

  • TG_PARALLELISM

--queue-exclude-dir

Unix-style glob of directories to exclude from the queue of Units to run.

Type: list(string)

Environment Variables:

  • TG_QUEUE_EXCLUDE_DIR

--queue-exclude-external

Exclude external dependencies from the queue of Units to run.

Type: bool

Environment Variables:

  • TG_QUEUE_EXCLUDE_EXTERNAL

--queue-excludes-file

Path to a file with a list of directories that need to be excluded when running `run --all` commands.

Type: string
Default: .terragrunt-excludes

Environment Variables:

  • TG_QUEUE_EXCLUDES_FILE

--queue-ignore-dag-order

Ignore DAG order for --all commands.

When enabled, Terragrunt will ignore the dependency order when running commands with --all. This means units will be executed in arbitrary order, which can be useful for read-only operations like plan.

Note that this can lead to errors if used with commands that modify state, as dependencies might be processed in the wrong order.

To learn more about how to use this flag, see the Stacks feature documentation.

Type: bool

Environment Variables:

  • TG_QUEUE_IGNORE_DAG_ORDER

--queue-ignore-errors

Continue processing Units even if a dependency fails.

When enabled, Terragrunt will continue processing remaining units even if one fails. This can be useful when you want to see all potential errors in your configuration, rather than stopping at the first failure.

Note that this may lead to incomplete or inconsistent states if used with commands that modify infrastructure.

To learn more about how to use this flag, see the Stacks feature documentation.

Type: bool

Environment Variables:

  • TG_QUEUE_IGNORE_ERRORS

--queue-include-dir

Unix-style glob of directories to include in the queue of Units to run.

Type: list(string)

Environment Variables:

  • TG_QUEUE_INCLUDE_DIR

--queue-include-external

Include external dependencies in the queue of Units to run.

Type: bool

Environment Variables:

  • TG_QUEUE_INCLUDE_EXTERNAL

--queue-include-units-reading

If flag is set, 'run --all' will only run the command against Terragrunt units that read the specified file via an HCL function or include.

Type: string

Environment Variables:

  • TG_QUEUE_INCLUDE_UNITS_READING

--queue-strict-include

Only process the directories matched by --queue-include-dir.

Type: bool

Environment Variables:

  • TG_QUEUE_STRICT_INCLUDE