Skip to content

Commit 970420f

Browse files
authored
Terraform validate script (#47)
1 parent 4e35ef2 commit 970420f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.github/workflows/pre-commit.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030

3131
- uses: actions/setup-python@v3
3232

33+
# Run terraform validate script so same script can be used in pre-commit
34+
# as in nightly pipeline
35+
- name: "Terraform validate"
36+
run: "tests/terraform_validate.sh"
37+
3338
- uses: pre-commit/[email protected]
3439
with:
3540
extra_args: "--hook-stage manual --all-files"

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ repos:
2828
- id: terraform_docs
2929
args:
3030
- "--args=--show=requirements,inputs,outputs"
31-
- id: terraform_validate
32-
args:
33-
- "--hook-config=--retry-once-with-cleanup=true"
34-
stages: ["manual"]
3531
- id: terraform_tflint
3632
stages: ["manual"]
3733

tests/terraform_validate.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Validate all Terraform modules in the repository
3+
4+
set -e
5+
6+
ROOT_DIR="$(git rev-parse --show-toplevel)"
7+
8+
find "$ROOT_DIR" -type d -name '.*' -prune -o -type f -name '*.tf' -print0 \
9+
| xargs -0 -r -n1 dirname | sort -u | while read -r module_dir; do
10+
echo "Validating module: $module_dir"
11+
(cd "$module_dir" && terraform init -backend=false -input=false -no-color > /dev/null 2>&1 && terraform validate -no-color)
12+
done

0 commit comments

Comments
 (0)