Skip to content

Commit f6caf21

Browse files
feat: add terragrunt validate hook (antonbabenko#134)
1 parent 2e40ade commit f6caf21

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
files: (\.hcl)$
5959
exclude: \.terraform\/.*$
6060

61+
- id: terragrunt_validate
62+
name: Terragrunt validate
63+
description: Validates all Terragrunt configuration files.
64+
entry: terragrunt_validate.sh
65+
language: script
66+
files: (\.hcl)$
67+
exclude: \.terraform\/.*$
68+
6169
- id: terraform_tfsec
6270
name: Terraform validate with tfsec
6371
description: Static analysis of Terraform templates to spot potential security issues.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ There are several [pre-commit](https://pre-commit.com/) hooks to keep Terraform
7474
| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md |
7575
| `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/terraform-linters/tflint). |
7676
| `terragrunt_fmt` | Rewrites all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) to a canonical format. |
77+
| `terragrunt_validate` | Validates all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) |
7778
| `terraform_tfsec` | [TFSec](https://github.com/liamg/tfsec) static analysis of terraform templates to spot potential security issues. |
7879

7980
Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blob/master/.pre-commit-hooks.yaml) to know arguments used for each hook.

terragrunt_validate.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
declare -a paths
6+
7+
index=0
8+
9+
for file_with_path in "$@"; do
10+
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
11+
12+
paths[index]=$(dirname "$file_with_path")
13+
14+
let "index+=1"
15+
done
16+
17+
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
18+
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
19+
20+
pushd "$path_uniq" > /dev/null
21+
terragrunt validate
22+
popd > /dev/null
23+
done

0 commit comments

Comments
 (0)