Skip to content

Commit 11a1609

Browse files
authored
Merge pull request #398 from cagov/tf_as_workflow
Update terraform CI to execute in its own job
2 parents 0eec35b + a279f89 commit 11a1609

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

.github/workflows/pre-commit.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ jobs:
2323
- uses: snok/install-poetry@v1
2424
with:
2525
virtualenvs-create: false
26-
- name: Setup terraform
27-
uses: hashicorp/setup-terraform@v2
28-
with:
29-
terraform_version: v1.4.0
30-
- name: Install tflint
31-
run: |
32-
curl -s https://raw.githubusercontent.com/terraform-linters/\
33-
tflint/master/install_linux.sh | bash
3426
- name: Install dependencies
3527
run: |
3628
poetry install
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: terraform-validation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
terraform-validation:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Setup terraform
15+
uses: hashicorp/setup-terraform@v2
16+
with:
17+
terraform_version: v1.4.0
18+
- name: Install tflint
19+
run: |
20+
curl -s https://raw.githubusercontent.com/terraform-linters/\
21+
tflint/master/install_linux.sh | bash
22+
23+
- name: Run terraform fmt
24+
run: |
25+
terraform fmt
26+
- name: Run terraform validate
27+
run: |
28+
terraform validate
29+
- name: Run terraform tflint
30+
run: |
31+
tflint --chdir=terraform/ --recursive
32+
33+
- name: Document cloud infrastructure remote state in README
34+
uses: terraform-docs/gh-actions@v1.3.0
35+
with:
36+
working-dir: ./terraform/s3-remote-state
37+
- name: Document cloud infrastructure in mkdocs
38+
uses: terraform-docs/gh-actions@v1.3.0
39+
with:
40+
working-dir: ./terraform/aws/modules/infra
41+
output-file: ../../../../docs/code/terraform-local-setup.md
42+
- name: Document Snowflake account infrastructure in mkdocs
43+
uses: terraform-docs/gh-actions@v1.3.0
44+
with:
45+
working-dir: ./terraform/snowflake/modules/elt
46+
output-file: ../../../../docs/infra/snowflake.md
47+
# This shouldn't be necessary but the terraform-docs action has a bug
48+
# preventing it from git-adding files outside of 'working-dir'.
49+
# See: https://github.com/terraform-docs/gh-actions/pull/108
50+
- name: Commit any files changed by terraform-docs
51+
run: |
52+
git add docs/code/terraform-local-setup.md
53+
git add docs/infra/snowflake.md
54+
# Run git commit if changed files are detected
55+
if git status --porcelain | grep -q '[AM ][AM ]\s\+\S\+'; then
56+
git config --global user.name 'github-actions[bot]'
57+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
58+
set -x
59+
git commit -m "Automated terraform-docs commit"
60+
git push
61+
set +x
62+
fi

.pre-commit-config.yaml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,6 @@ repos:
1111
- id: check-merge-conflict
1212
- id: detect-aws-credentials
1313
args: [--allow-missing-credentials]
14-
- repo: https://github.com/antonbabenko/pre-commit-terraform
15-
rev: v1.77.1
16-
hooks:
17-
- id: terraform_fmt
18-
- id: terraform_validate
19-
# Exclude modules to work around
20-
# https://github.com/hashicorp/terraform/issues/28490
21-
exclude: "terraform/[^/]+/modules/[^/]+/[^/]+$"
22-
- id: terraform_tflint
23-
- repo: https://github.com/terraform-docs/terraform-docs
24-
rev: v0.16.0
25-
hooks:
26-
- id: terraform-docs-go
27-
name: Document cloud infrastructure remote state in README
28-
args: ["./terraform/s3-remote-state"]
29-
- id: terraform-docs-go
30-
name: Document cloud infrastructure in mkdocs
31-
args:
32-
[
33-
"./terraform/aws/modules/infra/",
34-
"--output-file",
35-
"../../../../docs/cloud-infrastructure.md",
36-
]
37-
- id: terraform-docs-go
38-
name: Document Snowflake account infrastructure in mkdocs
39-
args:
40-
[
41-
"./terraform/snowflake/modules/elt/",
42-
"--output-file",
43-
"../../../../docs/snowflake.md",
44-
]
4514
- repo: https://github.com/charliermarsh/ruff-pre-commit
4615
rev: v0.1.6
4716
hooks:

0 commit comments

Comments
 (0)