diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 4369feaf..5e6849ef 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -26,6 +26,18 @@ files: \.tf$ exclude: \.+.terraform\/.*$ +- id: terragrunt-hclfmt + name: Terragrunt hclfmt + description: Rewrites all Terragrunt configuration files to a canonical format + entry: hooks/terragrunt-hclfmt.sh + language: script + files: \.hcl$ + exclude: > + (?x)^( + .+\.terraform\/.*$| + .+\.terragrunt-cache\/.*$| + )$ + - id: shellcheck name: Shellcheck Bash Linter description: Performs linting on bash scripts diff --git a/hooks/terragrunt-hclfmt.sh b/hooks/terragrunt-hclfmt.sh new file mode 100755 index 00000000..52821411 --- /dev/null +++ b/hooks/terragrunt-hclfmt.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions, +# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a +# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here. +export PATH=$PATH:/usr/local/bin + +for file in "$@"; do + terragrunt hclfmt --terragrunt-hclfmt-file "$file" +done