Skip to content

Commit 1062643

Browse files
authored
Merge pull request #4 from chris-qa-org/add-terraform-ci-github-actions
Add Terraform CI GitHub actions
2 parents 40957d6 + caedce0 commit 1062643

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

.github/workflows/main.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Terraform CI
2+
3+
on:
4+
push:
5+
branches: main
6+
pull_request:
7+
8+
jobs:
9+
validate-terraform:
10+
name: Validate Terraform
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v1
15+
16+
- name: Check for terraform version mismatch
17+
run: |
18+
DOTFILE_VERSION=$(cat .terraform-version)
19+
TERRAFORM_IMAGE_REFERENCES=$(grep "uses: docker://hashicorp/terraform" .github/workflows/main.yml | grep -v TERRAFORM_IMAGE_REFERENCES | wc -l | tr -d ' ')
20+
if [ "$(grep "docker://hashicorp/terraform:${DOTFILE_VERSION}" .github/workflows/main.yml | wc -l | tr -d ' ')" != "$TERRAFORM_IMAGE_REFERENCES" ]
21+
then
22+
echo -e "\033[1;31mError: terraform version in .terraform-version file does not match docker://hashicorp/terraform versions in .github/workflows/main.yml"
23+
exit 1
24+
fi
25+
26+
- name: Run a Terraform init
27+
uses: docker://hashicorp/terraform:1.1.7
28+
with:
29+
entrypoint: terraform
30+
args: init
31+
32+
- name: Run a Terraform validate
33+
uses: docker://hashicorp/terraform:1.1.7
34+
with:
35+
entrypoint: terraform
36+
args: validate
37+
38+
- name: Run a Terraform format check
39+
uses: docker://hashicorp/terraform:1.1.7
40+
with:
41+
entrypoint: terraform
42+
args: fmt -check=true -diff=true
43+
validate-terraform-docs:
44+
name: Validate Terraform Docs
45+
needs: validate-terraform
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Check out code
49+
uses: actions/checkout@v2
50+
with:
51+
ref: ${{ github.event.pull_request.head.ref }}
52+
53+
- name: Generate Terraform docs
54+
uses: terraform-docs/[email protected]
55+
with:
56+
working-dir: .
57+
config-file: .terraform-docs.yml
58+
output-file: README.md
59+
output-method: inject
60+
fail-on-diff: true

0 commit comments

Comments
 (0)