Skip to content
Latchkey

terragrunt hclfmt: Format terragrunt.hcl Files

terragrunt hclfmt formats all terragrunt.hcl and .hcl files in a tree to the canonical HCL style.

terraform fmt ignores terragrunt.hcl, so Terragrunt ships its own formatter. Run it the same way you run terraform fmt in CI: with a check flag that fails on unformatted files.

What it does

terragrunt hclfmt walks the working directory, finds .hcl files (including terragrunt.hcl), and rewrites each to canonical formatting in place. With --terragrunt-check it makes no changes and exits non-zero if any file would change, which is the CI gate.

Common usage

Terminal
# format in place
terragrunt hclfmt
# CI gate: fail if anything is unformatted
terragrunt hclfmt --terragrunt-check
# show what would change
terragrunt hclfmt --terragrunt-diff

Options

FlagWhat it does
--terragrunt-checkDo not write; exit non-zero if files need formatting
--terragrunt-diffPrint a diff of the changes that would be made
--terragrunt-hclfmt-file <file>Format a single specific file
--terragrunt-working-dir <dir>Limit the scan to a directory

In CI

Run terragrunt hclfmt --terragrunt-check as a lint stage so a mis-indented terragrunt.hcl fails fast instead of surfacing in a confusing plan diff. Pair it with terraform fmt -check -recursive for the .tf files, since the two formatters do not overlap.

Common errors in CI

A non-zero exit with no obvious message from --terragrunt-check simply means a file is unformatted; run terragrunt hclfmt --terragrunt-diff to see which. A parse error like "Invalid expression" means the HCL is syntactically broken, not just unformatted, and fmt cannot fix it; correct the syntax first.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →