mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
Formatter for Terragrunt HCL files (#60)
* Formatter for Terragrunt HCL files * Adding Terragrunt documentation
This commit is contained in:
parent
4bebeac734
commit
d8dfc2c034
3 changed files with 32 additions and 0 deletions
|
|
@ -41,3 +41,11 @@
|
||||||
language: script
|
language: script
|
||||||
files: (\.tf|\.tfvars)$
|
files: (\.tf|\.tfvars)$
|
||||||
exclude: \.terraform\/.*$
|
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\/.*$
|
||||||
|
|
|
||||||
|
|
@ -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` - 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_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
|
* `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.
|
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
23
terragrunt_fmt.sh
Executable 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue