Formatter for Terragrunt HCL files (#60)

* Formatter for Terragrunt HCL files

* Adding Terragrunt documentation
This commit is contained in:
Scott Crooks 2019-08-20 20:38:40 +02:00 committed by Anton Babenko
commit d8dfc2c034
3 changed files with 32 additions and 0 deletions

View file

@ -41,3 +41,11 @@
language: script
files: (\.tf|\.tfvars)$
exclude: \.terraform\/.*$
- id: terragrunt_fmt
name: Terragrunt fmt
description: Rewrites all Terragrunt configuration files to a canonical format.
entry: terragrunt_fmt.sh
language: script
files: (\.hcl)$
exclude: \.terraform\/.*$

View file

@ -52,6 +52,7 @@ There are several [pre-commit](http://pre-commit.com/) hooks to keep Terraform c
* `terraform_docs` - Inserts input and output documentation into `README.md`. Recommended.
* `terraform_docs_without_aggregate_type_defaults` - Inserts input and output documentation into `README.md` without aggregate type defaults.
* `terraform_docs_replace` - Runs `terraform-docs` and pipes the output directly to README.md
* `terragrunt_fmt` - Rewrites all Terragrunt configuration files to a canonical format.
Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blob/master/.pre-commit-hooks.yaml) to know arguments used for each hook.

23
terragrunt_fmt.sh Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
declare -a paths
index=0
for file_with_path in "$@"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
paths[index]=$(dirname "$file_with_path")
let "index+=1"
done
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
pushd "$path_uniq" > /dev/null
terragrunt hclfmt
popd > /dev/null
done