-
Notifications
You must be signed in to change notification settings - Fork 12
83 lines (70 loc) · 2.08 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
name: Main Branch Workflow
on:
push:
branches:
- main
- tflint-cache-fix
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:
runs-on: ubuntu-latest
needs: lint-find-dirs
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: Create TFLint Plugin Directory
run: mkdir -p ${{ env.TFLINT_PLUGIN_DIR }}
- name: Set current date as env variable
run: echo "TODAY=$(date +'%Y-%b-%d' | awk '{print toupper($0)}')" >> $GITHUB_ENV
- name: cache tflint plugins
id: cache-plugins
uses: actions/cache@v3
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: true
working_directory: ${{ matrix.tfdir }}
filter_mode: nofilter