Skip to content

Commit 303815c

Browse files
committed
ci: refactor terraform validation
1 parent 002b001 commit 303815c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

.github/workflows/terraform-validate-template.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ on:
2020
required: false
2121
type: boolean
2222
default: false
23+
tflint-options:
24+
description: "TFLint options"
25+
required: false
26+
type: string
27+
default: ""
2328

2429
jobs:
2530
verify:
@@ -59,4 +64,4 @@ jobs:
5964
- name: Run TFLint
6065
run: |
6166
tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl
62-
tflint -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars
67+
tflint -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars ${{ inputs.tflint-options }}

.github/workflows/terraform.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ jobs:
3939
needs: dirs
4040
with:
4141
terraform_version: ${{ matrix.terraform }}
42-
module: ${{ matrix.module }}
42+
module: ${{ matrix.modules }}
43+
tflint-options: ${{ matrix.modules == '.' && '' || '--recursive' }}
4344
strategy:
4445
fail-fast: false
4546
matrix:
46-
module: ${{ fromJson(needs.dirs.outputs.tf_modules) }}
47+
modules: [ ".", "modules", "examples"]
4748
terraform: ["1.5", "latest"]

.utils/terraform.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,32 @@ generateDummyLambdaZip() {
1010
touch "$lambdaDir/$(basename $lambdaDir).zip"
1111
done
1212
}
13+
14+
tfLintModules() {
15+
examples=($( findAllTerraformDirs --ignores modules --hide-root --format plain))
16+
ignore_commands=""
17+
# example
18+
# tflint --ignore-module terraform-aws-modules/vpc/aws --ignore-module terraform-aws-modules/security-group/aws
19+
# otuput of find
20+
# ./examples/arm64
21+
# ./examples/arm64/lambdas-download
22+
# ./examples/base
23+
# ./examples/default
24+
# ./examples/ephemeral
25+
# ./examples/lambdas-download
26+
# ./examples/multi-runner
27+
# ./examples/permissions-boundary
28+
# ./examples/permissions-boundary/setup
29+
# ./examples/prebuilt
30+
# ./examples/termination-watcher
31+
# ./examples/ubuntu
32+
# ./examples/windows
33+
# ./examples/windows/lambdas-download
34+
echo hi
35+
# for the ignore we need to strip ./ at the beginning
36+
for example in "${examples[@]}"; do
37+
ignore_commands="$ignore_commands --ignore-module=$example"
38+
done
39+
# run tflint
40+
echo tflint --recursive $ignore_commands --config "$(pwd)/.tflint.hcl"
41+
}

0 commit comments

Comments
 (0)