-
Notifications
You must be signed in to change notification settings - Fork 12
113 lines (95 loc) · 2.91 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Main Branch Workflow
on:
push:
branches:
- main
permissions:
pull-requests: write
id-token: write
contents: read
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Terraform format
uses: dflook/terraform-fmt@v1
- name: Status check
shell: bash
run: git diff --exit-code
lint-find-dirs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: |
matrix=$(find ./ -name '*.tf' \
-not -path '*/.terraform/*' \
-exec dirname {} \; \
| sort \
| uniq \
| jq --raw-input --slurp 'split("\n")| map(select(. != ""))')
echo "matrix=$(echo $matrix)" >> $GITHUB_OUTPUT
outputs:
tfdirs_matrix: ${{ steps.set-matrix.outputs.matrix }}
lint-init:
runs-on: ubuntu-latest
needs: lint-find-dirs
env:
TFLINT_PLUGIN_DIR: ${{ github.workspace }}/.tflint.d/plugins
TFLINT_PLUGINS: aws azurerm google
steps:
- name: Create TFLint Plugin Directory
run: mkdir -p ${{ env.TFLINT_PLUGIN_DIR }}
- name: Create temp empty folder
run: mkdir -p empty
- name: tflint init
uses: reviewdog/[email protected]
with:
reporter: "local"
fail_on_error: false
tflint_rulesets: ${{ env.TFLINT_PLUGINS }}
tflint_init: true
working_directory: "./empty"
filter_mode: nofilter
tflint_version: "v0.49.0"
- name: cache tflint plugins
id: cache-plugins
uses: actions/cache@v3
with:
path: ${{ env.TFLINT_PLUGIN_DIR }}
key: tflint-plugins-${{ env.TODAY }}
lint:
runs-on: ubuntu-latest
needs: [lint-find-dirs, lint-init]
strategy:
fail-fast: false
matrix:
tfdir: ${{ fromJson(needs.lint-find-dirs.outputs.tfdirs_matrix) }}
env:
TFLINT_PLUGIN_DIR: ${{ github.workspace }}/.tflint.d/plugins
TFLINT_PLUGINS: aws azurerm google
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2
- run: terraform init
working-directory: ${{ matrix.tfdir }}
- name: Set current date as env variable
run: echo "TODAY=$(date +'%Y-%b-%d' | awk '{print toupper($0)}')" >> $GITHUB_ENV
- name: Restore cached tflint plugins
id: cache-tflint-plugins-restore
uses: actions/cache/restore@v4
with:
path: ${{ env.TFLINT_PLUGIN_DIR }}
key: tflint-plugins-${{ env.TODAY }}
- name: tflint
uses: reviewdog/[email protected]
with:
reporter: "local"
fail_on_error: true
tflint_rulesets: ${{ env.TFLINT_PLUGINS }}
tflint_init: false
working_directory: ${{ matrix.tfdir }}
filter_mode: nofilter
tflint_version: "v0.49.0"