Skip to content

Commit f322ed8

Browse files
authored
chore: align ci-cd static checks to use individual minimum Terraform versions (#207)
1 parent 5a118fa commit f322ed8

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

.github/workflows/pre-commit.yml

+56-16
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,95 @@ on:
77
- master
88

99
jobs:
10-
getBaseVersion:
11-
name: Get min/max versions
12-
runs-on: ubuntu-latest
10+
# Min Terraform version(s)
11+
getDirectories:
12+
name: Get root directories
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Install Python
18+
uses: actions/setup-python@v2
19+
- name: Build matrix
20+
id: matrix
21+
run: |
22+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
23+
echo "::set-output name=directories::$DIRS"
24+
outputs:
25+
directories: ${{ steps.matrix.outputs.directories }}
1326

27+
preCommitMinVersions:
28+
name: Min TF validate
29+
needs: getDirectories
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
1434
steps:
1535
- name: Checkout
1636
uses: actions/checkout@v2
37+
- name: Install Python
38+
uses: actions/setup-python@v2
39+
- name: Terraform min/max versions
40+
id: minMax
41+
uses: clowdhaus/terraform-min-max@v1.0.1
42+
with:
43+
directory: ${{ matrix.directory }}
44+
- name: Install Terraform v${{ steps.minMax.outputs.minVersion }}
45+
uses: hashicorp/setup-terraform@v1
46+
with:
47+
terraform_version: ${{ steps.minMax.outputs.minVersion }}
48+
- name: Install pre-commit dependencies
49+
run: pip install pre-commit
50+
- name: Execute pre-commit
51+
# Run only validate pre-commit check on min version supported
52+
if: ${{ matrix.directory != '.' }}
53+
run:
54+
pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
55+
- name: Execute pre-commit
56+
# Run only validate pre-commit check on min version supported
57+
if: ${{ matrix.directory == '.' }}
58+
run:
59+
pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
60+
1761

62+
# Max Terraform version
63+
getBaseVersion:
64+
name: Module max TF version
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v2
1869
- name: Terraform min/max versions
1970
id: minMax
2071
uses: clowdhaus/terraform-min-max@v1.0.1
2172
outputs:
2273
minVersion: ${{ steps.minMax.outputs.minVersion }}
2374
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
2475

25-
preCommit:
26-
name: Pre-commit check
76+
preCommitMaxVersion:
77+
name: Max TF pre-commit
2778
runs-on: ubuntu-latest
2879
needs: getBaseVersion
2980
strategy:
3081
fail-fast: false
3182
matrix:
3283
version:
33-
- ${{ needs.getBaseVersion.outputs.minVersion }}
3484
- ${{ needs.getBaseVersion.outputs.maxVersion }}
35-
3685
steps:
3786
- name: Checkout
3887
uses: actions/checkout@v2
39-
4088
- name: Install Python
4189
uses: actions/setup-python@v2
42-
4390
- name: Install Terraform v${{ matrix.version }}
4491
uses: hashicorp/setup-terraform@v1
4592
with:
4693
terraform_version: ${{ matrix.version }}
47-
4894
- name: Install pre-commit dependencies
4995
run: |
5096
pip install pre-commit
5197
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
5298
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
53-
54-
- name: Execute pre-commit
55-
# Run only validate pre-commit check on min version supported
56-
if: ${{ matrix.version == needs.getBaseVersion.outputs.minVersion }}
57-
run: pre-commit run --color=always --show-diff-on-failure --all-files terraform_validate
58-
5999
- name: Execute pre-commit
60100
# Run all pre-commit checks on max version supported
61101
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.46.0
3+
rev: v1.47.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

0 commit comments

Comments
 (0)