Skip to content

Commit

Permalink
Update hclfmt documentation (#3702)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbcz1989 authored Jan 6, 2025
1 parent 95eda4c commit 1219673
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/_docs/01_getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ This allows Terragrunt to avoid resolving `dependency` on units that haven’t b

You can rewrite the HCL files to a canonical format using the `hclfmt` command built into `terragrunt`. Similar to `tofu fmt`, this command applies a subset of [the OpenTofu/Terraform language style conventions](https://www.terraform.io/docs/configuration/style.html), along with other minor adjustments for readability.

This command will recursively search for hcl files and format all of them under a given directory tree. Consider the following file structure:
By default, this command will recursively search for hcl files and format all of them under a given directory tree. Consider the following file structure:

```tree
root
Expand Down Expand Up @@ -121,3 +121,9 @@ If you run `terragrunt hclfmt` at the `root`, this will update:
You can set `--terragrunt-diff` option. `terragrunt hclfmt --terragrunt-diff` will output the diff in a unified format which can be redirected to your favourite diff tool. `diff` utility must be presented in PATH.

Additionally, there’s a flag `--terragrunt-check`. `terragrunt hclfmt --terragrunt-check` will only verify if the files are correctly formatted **without rewriting** them. The command will return exit status 1 if any matching files are improperly formatted, or 0 if all matching `.hcl` files are correctly formatted.

You can exclude directories from the formatting process by using the `--terragrunt-hclfmt-exclude-dir` flag. For example, `terragrunt hclfmt --terragrunt-hclfmt-exclude-dir=qa/services`.

If you want to format a single file, you can use the `--terragrunt-hclfmt-file` flag. For example, `terragrunt hclfmt --terragrunt-hclfmt-file qa/services/services.hcl`.

If you want to format HCL from stdin and print the result to stdout, you can use the `--terragrunt-hclfmt-stdin` flag. For example, `echo 'module "foo" {}' | terragrunt hclfmt --terragrunt-hclfmt-stdin`.

0 comments on commit 1219673

Please sign in to comment.