Skip to content

Commit 5a118fa

Browse files
authored
chore: add ci-cd workflow for pre-commit checks (#201)
1 parent 043f64f commit 5a118fa

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

.github/workflows/pre-commit.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
getBaseVersion:
11+
name: Get min/max versions
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Terraform min/max versions
19+
id: minMax
20+
uses: clowdhaus/terraform-min-max@v1.0.1
21+
outputs:
22+
minVersion: ${{ steps.minMax.outputs.minVersion }}
23+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
24+
25+
preCommit:
26+
name: Pre-commit check
27+
runs-on: ubuntu-latest
28+
needs: getBaseVersion
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
version:
33+
- ${{ needs.getBaseVersion.outputs.minVersion }}
34+
- ${{ needs.getBaseVersion.outputs.maxVersion }}
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
40+
- name: Install Python
41+
uses: actions/setup-python@v2
42+
43+
- name: Install Terraform v${{ matrix.version }}
44+
uses: hashicorp/setup-terraform@v1
45+
with:
46+
terraform_version: ${{ matrix.version }}
47+
48+
- name: Install pre-commit dependencies
49+
run: |
50+
pip install pre-commit
51+
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/
52+
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+
59+
- name: Execute pre-commit
60+
# Run all pre-commit checks on max version supported
61+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
62+
run: pre-commit run --color=always --show-diff-on-failure --all-files

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ No Modules.
113113

114114
| Name |
115115
|------|
116-
| [aws_instance](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/instance) |
116+
| [aws_instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) |
117117

118118
## Inputs
119119

examples/basic/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Note that this example may create resources which can cost money. Run `terraform
4444

4545
| Name |
4646
|------|
47-
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/ami) |
48-
| [aws_eip](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/eip) |
49-
| [aws_kms_key](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/kms_key) |
50-
| [aws_network_interface](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/network_interface) |
51-
| [aws_placement_group](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/placement_group) |
52-
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/subnet_ids) |
53-
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/vpc) |
47+
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) |
48+
| [aws_eip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eip) |
49+
| [aws_kms_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) |
50+
| [aws_network_interface](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_interface) |
51+
| [aws_placement_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/placement_group) |
52+
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) |
53+
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) |
5454

5555
## Inputs
5656

examples/volume-attachment/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Note that this example may create resources which can cost money. Run `terraform
4343

4444
| Name |
4545
|------|
46-
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/ami) |
47-
| [aws_ebs_volume](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/ebs_volume) |
48-
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/subnet_ids) |
49-
| [aws_volume_attachment](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/resources/volume_attachment) |
50-
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/2.65/docs/data-sources/vpc) |
46+
| [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) |
47+
| [aws_ebs_volume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ebs_volume) |
48+
| [aws_subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) |
49+
| [aws_volume_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/volume_attachment) |
50+
| [aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) |
5151

5252
## Inputs
5353

0 commit comments

Comments
 (0)