Skip to content

Commit

Permalink
Formatter for Terragrunt HCL files (#60)
Browse files Browse the repository at this point in the history
* Formatter for Terragrunt HCL files

* Adding Terragrunt documentation
  • Loading branch information
sc250024 authored and antonbabenko committed Aug 20, 2019
1 parent 4bebeac commit d8dfc2c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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\/.*$
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
23 changes: 23 additions & 0 deletions terragrunt_fmt.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d8dfc2c

Please sign in to comment.