Skip to content

Commit 01afb44

Browse files
author
iru
authored
ci: test validate (#69)
* ci: test validate
1 parent 3727bde commit 01afb44

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

.github/workflows/ci-pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
paths:
66
- '**.tf'
7+
- '.pre-commit-config.yaml'
78
push:
89
branches:
910
- master

.pre-commit-config.yaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ repos:
1212
# "Error: Provider configuration not present" error
1313
# https://github.com/hashicorp/terraform/issues/21416
1414
# https://discuss.hashicorp.com/t/how-to-run-terraform-validate-on-a-module-that-is-supplied-the-providers-via-an-alias/34664/2
15-
- repo: local
16-
hooks:
17-
- id: terraform_validate
18-
name: Terraform validate
19-
entry: .pre-commit-terraform-validate-examples.sh
20-
pass_filenames: false
21-
language: script
15+
# - repo: local
16+
# hooks:
17+
# - id: terraform_validate
18+
# name: Terraform validate
19+
# entry: .pre-commit-terraform-validate-examples.sh
20+
# pass_filenames: false
21+
# language: script
22+
# verbose: true
2223

2324
- repo: git://github.com/antonbabenko/pre-commit-terraform
24-
rev: v1.50.0
25+
rev: v1.64.0
2526
hooks:
2627
- id: terraform_fmt
27-
# - id: terraform_validate
28+
# https://github.com/antonbabenko/pre-commit-terraform#terraform_validate
29+
- id: terraform_validate
30+
exclude: (modules/infrastructure/permissions/org-role-ecs)|(examples/organizational)|(test)|(examples-internal)\/.*$
2831
- id: terraform_docs
2932
args:
3033
- '--args=--sort-by required'
@@ -45,7 +48,7 @@ repos:
4548
- '--args=--only=terraform_standard_module_structure'
4649
- '--args=--only=terraform_workspace_remote'
4750
- repo: git://github.com/pre-commit/pre-commit-hooks
48-
rev: v4.0.1
51+
rev: v4.1.0
4952
hooks:
5053
- id: check-merge-conflict
5154
- id: end-of-file-fixer

.pre-commit-terraform-validate-examples.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
set -o errexit
55

66
# cleanup
7+
echo "cleaning .terraform state"
78
bash ./resources/terraform-clean.sh
89

9-
for dir in examples*/*
10+
for dir in $(find . -name 'versions.tf' -not -path '*.terraform*' -exec dirname {} \;)
1011
do
11-
12+
echo validating [$dir]
1213
# skip aliased providers due to terraform validate unresolved bug
1314
# https://github.com/hashicorp/terraform/issues/28490
14-
if [ $dir == "examples/organizational" ]; then
15+
if [ "$dir" == "examples/organizational" ]; then
1516
echo "skipping validation on [$dir]"
1617
break
1718
fi
18-
echo validating example [$dir]
19-
cd $dir
20-
terraform init
19+
pushd .
20+
cd "$dir"
21+
# force init
22+
# https://github.com/antonbabenko/pre-commit-terraform/issues/224
23+
terraform init --upgrade
2124
terraform validate
22-
cd ../..
25+
popd
2326
done

0 commit comments

Comments
 (0)