Skip to content

Commit 4a0bdcd

Browse files
committed
Pre-commit hook for running terragrunt hclfmt
1 parent 811a1fb commit 4a0bdcd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
files: \.tf$
2727
exclude: \.+.terraform\/.*$
2828

29+
- id: terragrunt-hclfmt
30+
name: Terragrunt hclfmt
31+
description: Rewrites all Terragrunt configuration files to a canonical format
32+
entry: hooks/terragrunt-hclfmt.sh
33+
language: script
34+
files: \.hcl$
35+
exclude: >
36+
(?x)^(
37+
.+\.terraform\/.*$|
38+
.+\.terragrunt-cache\/.*$|
39+
)$
40+
2941
- id: shellcheck
3042
name: Shellcheck Bash Linter
3143
description: Performs linting on bash scripts

hooks/terragrunt-hclfmt.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
6+
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
7+
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
8+
export PATH=$PATH:/usr/local/bin
9+
10+
for file in "$@"; do
11+
terragrunt hclfmt --terragrunt-config "$file"
12+
done

0 commit comments

Comments
 (0)