generated from aws-ia/terraform-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 507
98 lines (85 loc) · 3.16 KB
/
pre-commit.yaml
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
name: pre-commit
on:
pull_request:
branches:
- main
env:
TERRAFORM_DOCS_VERSION: v0.16.0
TFLINT_VERSION: v0.45.0
jobs:
collectInputs:
name: Collect workflow inputs
runs-on: ubuntu-latest
outputs:
directories: ${{ steps.dirs.outputs.directories }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get root directories
id: dirs
uses: clowdhaus/terraform-composite-actions/[email protected]
preCommitMinVersions:
name: Min TF pre-commit
needs: collectInputs
runs-on: ubuntu-latest
strategy:
matrix:
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
# We only need to check Terraform files for the current directory
# because the `preCommitMaxVersion` job will run the full,
# exhaustive checks (always)
filters: |
src:
- '${{ matrix.directory }}/*.tf'
- name: Terraform min/max versions
uses: clowdhaus/[email protected]
if: steps.changes.outputs.src == 'true'
id: minMax
with:
directory: ${{ matrix.directory }}
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
uses: clowdhaus/terraform-composite-actions/[email protected]
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory != '.' && steps.changes.outputs.src == 'true' }}
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
uses: clowdhaus/terraform-composite-actions/[email protected]
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory == '.' && steps.changes.outputs.src == 'true' }}
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
preCommitMaxVersion:
name: Max TF pre-commit
runs-on: ubuntu-latest
needs: collectInputs
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
src:
- '**/*.tf'
- name: Terraform min/max versions
id: minMax
uses: clowdhaus/[email protected]
if: steps.changes.outputs.src == 'true'
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
uses: clowdhaus/terraform-composite-actions/[email protected]
if: steps.changes.outputs.src == 'true'
with:
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
tflint-version: ${{ env.TFLINT_VERSION }}