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

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

--queue-exclude-dir

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

Specifies directories to exclude when running commands with all.

This flag can be specified multiple times to exclude multiple directories. When using the TG_QUEUE_EXCLUDE_DIR environment variable, specify the directories as a comma-separated list.

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

Type: list(string)

Environment Variables:

  • TG_QUEUE_EXCLUDE_DIR

--queue-exclude-external

Exclude external dependencies from the queue of Units to run.

When enabled, Terragrunt will exclude external dependencies (dependencies outside the current working directory) from the queue when running commands with all.

Note that an external dependency is a dependency that is outside the current Terragrunt working directory and is not within any directories specified by queue-include-dir.

This flag is useful when you want to limit the scope of execution to only units within your current working directory structure.

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.

Units in these directories will be excluded during execution of the commands. If a relative path is specified, it should be relative from —working-dir. This will only exclude the module, not its dependencies.

This flag has been designed to integrate nicely with the hcl validate command, which can return a list of invalid files delimited by newlines when passed the --show-config-path flag. To integrate the two, you can run something like the following using bash process substitution:

Terminal window
terragrunt run --all plan --queue-excludes-file <(terragrunt hcl validate --show-config-path || true)
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.

Specifies directories to include when running commands with --all.

This flag can be specified multiple times to include multiple directories. When using the TG_QUEUE_INCLUDE_DIR environment variable, specify the directories as a comma-separated list.

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

Type: list(string)

Environment Variables:

  • TG_QUEUE_INCLUDE_DIR

--queue-include-external

Include external dependencies in the queue of Units to run.

When enabled, Terragrunt will include external dependencies (dependencies discovered outside the current working directory) in the queue when running commands with --all or --graph.

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.

This flag works very similarly to the --queue-units-that-include flag, but instead of looking only for included configurations, it also looks for configurations that read a given file.

When passed in, the --all command will include all units (modules) that read a given file into the queue. This is useful when you want to trigger an update on all units that read or include a given file using HCL functions in their configurations.

Consider the following folder structure:

  • Directoryreading-shared-hcl
    • terragrunt.hcl
  • Directoryalso-reading-shared-hcl
    • terragrunt.hcl
  • Directorynot-reading-shared-hcl
    • terragrunt.hcl
  • shared.hcl

Suppose that reading-shared-hcl and also-reading-shared-hcl both read shared.hcl in their configurations, like so:

terragrunt.hcl
locals {
shared = read_terragrunt_config(find_in_parent_folders("shared.hcl"))
}

If you run the command run --all init --queue-include-units-reading shared.hcl from the root folder, both reading-shared-hcl and also-reading-shared-hcl will be run; not not-reading-shared-hcl.

This is because the read_terragrunt_config HCL function has a special hook that allows Terragrunt to track that it has read the file shared.hcl. This hook is used by all native HCL functions that Terragrunt supports which read files.

Note, however, that there are certain scenarios where Terragrunt may not be able to track that a file has been read this way.

For example, you may be using a bash script to read a file via run_cmd, or reading the file via OpenTofu code. To support these use-cases, the mark_as_read function can be used to manually mark a file as read.

That would look something like this:

terragrunt.hcl
locals {
filename = mark_as_read("file-read-by-tofu.txt")
}
inputs = {
filename = local.filename
}
Type: string

Environment Variables:

  • TG_QUEUE_INCLUDE_UNITS_READING

--queue-strict-include

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

When enabled, Terragrunt will only process directories that match the patterns specified by --queue-include-dir.

For example, with the following directory structure:

  • Directoryprod
    • Directoryapp
      • terragrunt.hcl
    • Directorydb
      • terragrunt.hcl
  • Directorystaging
    • Directoryapp
      • terragrunt.hcl
    • Directorydb
      • terragrunt.hcl

Running terragrunt run --all plan --queue-include-dir "prod/*" would process all directories, but the --all flag includes by default when no excludes are provided, so the stage stack would also be included by default.

Running terragrunt run --all plan --queue-include-dir "prod/*" --queue-strict-include tells Terragrunt to exclude by default, so it only include units prod/app and prod/db.

Type: bool

Environment Variables:

  • TG_QUEUE_STRICT_INCLUDE