Skip to content

Commit c9f783d

Browse files
authored
Setup actions for pre-commit (#34)
* Setup actions for pre-commit * Link check * To drop * Edit path * Pre-commit badge * Revert "Edit path" This reverts commit ccd5c09. * Revert "To drop" This reverts commit a3ccee0. * Setup plan for examples * Remove dead code
1 parent 54b38e7 commit c9f783d

File tree

7 files changed

+207
-171
lines changed

7 files changed

+207
-171
lines changed

.github/workflows/linkcheck.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"timeout": "5s",
3+
"retryOn429": true,
4+
"retryCount": 5,
5+
"fallbackRetryDelay": "30s",
6+
"aliveStatusCodes": [200, 206],
7+
"httpHeaders": [
8+
{
9+
"urls": ["https://help.github.com/"],
10+
"headers": {
11+
"Accept-Encoding": "zstd, br, gzip, deflate"
12+
}
13+
}
14+
],
15+
"ignorePatterns": [
16+
{
17+
"pattern": [
18+
"localhost"
19+
]
20+
},
21+
{
22+
"pattern": [
23+
"127.0.0.1"
24+
]
25+
}
26+
]
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check Markdown links
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "**/*.md"
9+
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- "**/*.md"
15+
16+
jobs:
17+
markdown-link-check:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-node@v3
22+
with:
23+
node-version: '16.x'
24+
- name: install markdown-link-check
25+
run: npm install -g [email protected]
26+
- name: markdown-link-check version
27+
run: npm list -g markdown-link-check
28+
- name: Run markdown-link-check on MD files
29+
run: find docs -name "*.md" | xargs -n 1 markdown-link-check -q -c .github/workflows/linkcheck.json

.github/workflows/pre-commit.yaml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- '**.tf'
9+
- '**.yml'
10+
- '**.yaml'
11+
12+
env:
13+
TERRAFORM_DOCS_VERSION: v0.16.0
14+
TFSEC_VERSION: v1.22.0
15+
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/.terraform.d/plugin-cache
16+
TFLINT_VERSION: v0.38.1
17+
18+
concurrency:
19+
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
20+
cancel-in-progress: true
21+
22+
jobs:
23+
collectInputs:
24+
name: Collect workflow inputs
25+
runs-on: ubuntu-latest
26+
outputs:
27+
directories: ${{ steps.dirs.outputs.directories }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v3
31+
32+
- name: Get root directories
33+
id: dirs
34+
uses: clowdhaus/terraform-composite-actions/[email protected]
35+
36+
preCommitMinVersions:
37+
name: Min TF pre-commit
38+
needs: collectInputs
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v3
46+
47+
- uses: dorny/paths-filter@v2
48+
id: changes
49+
with:
50+
# We only need to check Terraform files for the current directory
51+
# because the `preCommitMaxVersion` job will run the full,
52+
# exhaustive checks (always)
53+
filters: |
54+
src:
55+
- '${{ matrix.directory }}/*.tf'
56+
57+
- name: Config Terraform plugin cache
58+
if: steps.changes.outputs.src== 'true'
59+
run: mkdir --parents ${{ env.TERRAFORM_DOCS_VERSION }}
60+
61+
- name: Cache Terraform
62+
uses: actions/cache@v3
63+
if: steps.changes.outputs.src== 'true'
64+
with:
65+
path: ${{ env.TERRAFORM_DOCS_VERSION }}
66+
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
67+
restore-keys: ${{ runner.os }}-terraform-
68+
69+
- name: Terraform min/max versions
70+
uses: clowdhaus/[email protected]
71+
if: steps.changes.outputs.src== 'true'
72+
id: minMax
73+
with:
74+
directory: ${{ matrix.directory }}
75+
76+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
77+
uses: clowdhaus/terraform-composite-actions/[email protected]
78+
# Run only validate pre-commit check on min version supported
79+
if: ${{ matrix.directory != '.' && steps.changes.outputs.src== 'true' }}
80+
with:
81+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
82+
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
83+
84+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
85+
uses: clowdhaus/terraform-composite-actions/[email protected]
86+
# Run only validate pre-commit check on min version supported
87+
if: ${{ matrix.directory == '.' && steps.changes.outputs.src== 'true' }}
88+
with:
89+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
90+
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
91+
92+
preCommitMaxVersion:
93+
name: Max TF pre-commit
94+
runs-on: ubuntu-latest
95+
needs: collectInputs
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v3
99+
100+
- uses: dorny/paths-filter@v2
101+
id: changes
102+
with:
103+
filters: |
104+
src:
105+
- '**/*.tf'
106+
107+
- name: Config Terraform plugin cache
108+
if: steps.changes.outputs.src== 'true'
109+
run: mkdir --parents ${{ env.TERRAFORM_DOCS_VERSION }}
110+
111+
- name: Cache Terraform
112+
uses: actions/cache@v3
113+
if: steps.changes.outputs.src== 'true'
114+
with:
115+
path: ${{ env.TF_PLUGIN_CACHE_DIR }}
116+
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
117+
restore-keys: ${{ runner.os }}-terraform-
118+
119+
- name: Install tfsec
120+
if: steps.changes.outputs.src== 'true'
121+
run: curl -sSLo ./tfsec https://github.com/aquasecurity/tfsec/releases/download/${{ env.TFSEC_VERSION }}/tfsec-$(uname)-amd64 && chmod +x tfsec && sudo mv tfsec /usr/bin/
122+
123+
- name: Terraform min/max versions
124+
id: minMax
125+
uses: clowdhaus/[email protected]
126+
if: steps.changes.outputs.src== 'true'
127+
128+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
129+
uses: clowdhaus/terraform-composite-actions/[email protected]
130+
if: steps.changes.outputs.src== 'true'
131+
with:
132+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
133+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
134+
tflint-version: ${{ env.TFLINT_VERSION }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# AWS Observability Accelerator for Terraform
22

3+
[![pre-commit](https://github.com/aws-observability/terraform-aws-observability-accelerator/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/aws-observability/terraform-aws-observability-accelerator/actions/workflows/pre-commit.yaml)
4+
35
Welcome to the AWS Observability Accelerator for Terraform!
46

57
The AWS Observability accelerator for Terraform is a set of modules to help you

examples/eks-cluster-with-vpc/versions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ terraform {
2323
version = ">= 1.25.0"
2424
}
2525
}
26+
27+
# ## Used for end-to-end testing on project; update to suit your needs
28+
# backend "s3" {
29+
# bucket = "observability-accelerator-terraform-states"
30+
# region = "us-west-2"
31+
# key = "e2e/eks-cluster-with-vpc/terraform.tfstate"
32+
# }
2633
}

examples/existing-cluster-with-base-and-infra/versions.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ terraform {
2222
version = ">= 1.25.0"
2323
}
2424
}
25+
26+
# ## Used for end-to-end testing on project; update to suit your needs
27+
# backend "s3" {
28+
# bucket = "observability-accelerator-terraform-states"
29+
# region = "us-west-2"
30+
# key = "e2e/existing-cluster-with-base-and-infra/terraform.tfstate"
31+
# }
32+
2533
}

modules/workloads/haproxy/main.tf

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)