Skip to content

Commit 44af065

Browse files
authored
Merge pull request #4 from getindata/feat/add-tf-pre-commit-workflow
feat: Add Terraform pre commit validation workflow
2 parents 9d98c9a + 2796d1a commit 44af065

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

.github/workflows/gh-create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
if: ${{ steps.bump-semver.outputs.new_version != null }}
4444
with:
4545
token: "${{ secrets.GITHUB_TOKEN }}"
46-
exclude: '^meta|^docs|^document|^lint|^ci|^refactor|readme|workflow|bump|dependencies|yml|^v?\d+\.\d+\.\d+'
46+
exclude: '^meta|^docs|^document|^lint|^ci|^refactor|readme|bump|dependencies|^v?\d+\.\d+\.\d+'
4747
tag: "${{ steps.bump-semver.outputs.new_version }}"
4848
title: "Version ${{ steps.bump-semver.outputs.new_version }}"
4949
commit-template: "- {title} ← {hash}"

.github/workflows/tf-pre-commit.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Terraform Pre-Commit
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
terraform-docs-version:
7+
type: string
8+
required: false
9+
default: v0.16.0
10+
tflint-version:
11+
type: string
12+
required: false
13+
default: v0.48.0
14+
15+
jobs:
16+
collectInputs:
17+
name: Collect workflow inputs
18+
runs-on: ubuntu-latest
19+
outputs:
20+
directories: ${{ steps.dirs.outputs.directories }}
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Get root directories
26+
id: dirs
27+
uses: clowdhaus/terraform-composite-actions/[email protected]
28+
29+
preCommitMinVersions:
30+
name: Min TF pre-commit
31+
needs: collectInputs
32+
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Terraform min/max versions
41+
id: minMax
42+
uses: clowdhaus/[email protected]
43+
with:
44+
directory: ${{ matrix.directory }}
45+
46+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
47+
# Run only validate pre-commit check on min version supported
48+
if: ${{ matrix.directory != '.' }}
49+
uses: clowdhaus/terraform-composite-actions/[email protected]
50+
with:
51+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
52+
args: 'terraform-validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
53+
54+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
55+
# Run only validate pre-commit check on min version supported
56+
if: ${{ matrix.directory == '.' }}
57+
uses: clowdhaus/terraform-composite-actions/[email protected]
58+
with:
59+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
60+
args: 'terraform-validate --color=always --show-diff-on-failure --files $(ls *.tf)'
61+
62+
preCommitMaxVersion:
63+
name: Max TF pre-commit
64+
runs-on: ubuntu-latest
65+
needs: collectInputs
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v4
69+
with:
70+
ref: ${{ github.event.pull_request.head.ref }}
71+
repository: ${{github.event.pull_request.head.repo.full_name}}
72+
73+
- name: Terraform min/max versions
74+
id: minMax
75+
uses: clowdhaus/[email protected]
76+
77+
# Step required as tflint pre-commit hook requires module to be initialised
78+
- run: terraform init
79+
80+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
81+
uses: clowdhaus/terraform-composite-actions/[email protected]
82+
with:
83+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
84+
terraform-docs-version: ${{ inputs.terraform-docs-version }}
85+
tflint-version: ${{ inputs.tflint-version }}

0 commit comments

Comments
 (0)