Skip to content

Commit 7a741fd

Browse files
committed
ci: refactor terraform validation
1 parent df3e41c commit 7a741fd

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Validate Terraform module"
2+
on:
3+
workflow_call:
4+
inputs:
5+
terraform_version:
6+
description: "Terraform version"
7+
required: true
8+
type: string
9+
module:
10+
description: "Module to validate"
11+
required: true
12+
type: string
13+
runs-on:
14+
description: "Runs on"
15+
required: false
16+
type: string
17+
default: '["ubuntu-latest"]'
18+
continue-on-error:
19+
description: "Continue on error"
20+
required: false
21+
type: boolean
22+
default: false
23+
24+
jobs:
25+
verify:
26+
name: Verify ${{ inputs.module }}
27+
runs-on: ${{ fromJSON(inputs.runs-on) }}
28+
continue-on-error: ${{ inputs.continue-on-error }}
29+
30+
defaults:
31+
run:
32+
working-directory: ${{ inputs.module }}
33+
steps:
34+
- uses: hashicorp/setup-terraform@v3
35+
with:
36+
terraform_version: ${{ inputs.terraform_version }}
37+
#terraform_wrapper: false
38+
- name: "Checkout"
39+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
40+
- name: "Generate dummy lambda zip files"
41+
run: |
42+
source ${GITHUB_WORKSPACE}/.utils/terraform.sh
43+
generateDummyLambdaZip
44+
- name: Initialize Terraform
45+
run: terraform init -get -backend=false -input=false
46+
- name: Check Terraform formatting
47+
run: terraform fmt -check=true -write=false
48+
- name: Validate Terraform
49+
run: terraform validate
50+
- uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
51+
name: Cache TFLint plugin dir
52+
with:
53+
path: ~/.tflint.d/plugins
54+
key: tflint-${{ hashFiles('.tflint.hcl') }}
55+
- name: Setup TFLint
56+
uses: terraform-linters/setup-tflint@19a52fbac37dacb22a09518e4ef6ee234f2d4987 # v4.0.0
57+
with:
58+
github_token: ${{ secrets.GITHUB_TOKEN }}
59+
- name: Run TFLint
60+
run: |
61+
tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl
62+
tflint -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars

0 commit comments

Comments
 (0)