Skip to content

Commit

Permalink
Merge pull request #375 from DFE-Digital/github-ci-terraform
Browse files Browse the repository at this point in the history
Consolidated Terraform tasks into single workflow
  • Loading branch information
DrizzlyOwl authored Sep 4, 2023
2 parents 4fcb1ef + f446084 commit 5b30fe2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 57 deletions.
49 changes: 29 additions & 20 deletions .github/workflows/continuous-integration-terraform.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: Validate terraform
name: Continuous Integration / Terraform

on:
push:
branches: main
paths:
- 'terraform/**.tf'
pull_request:
paths:
- 'terraform/**.tf'

jobs:
terraform-validate:
name: Terraform Validate
name: Validate
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand All @@ -23,41 +27,46 @@ jobs:
exit 1
fi
- name: Validate Terraform docs
uses: terraform-docs/[email protected]
with:
working-dir: terraform
config-file: .terraform-docs.yml
output-file: README.md
output-method: inject
fail-on-diff: true

- name: Remove azure backend
run: rm ./terraform/backend.tf

- name: Run a Terraform init
uses: docker://hashicorp/terraform:1.5.5
uses: docker://hashicorp/terraform:1.5.6
with:
entrypoint: terraform
args: -chdir=terraform init

- name: Run a Terraform validate
uses: docker://hashicorp/terraform:1.5.5
uses: docker://hashicorp/terraform:1.5.6
with:
entrypoint: terraform
args: -chdir=terraform validate

- name: Run a Terraform format check
uses: docker://hashicorp/terraform:1.5.5
uses: docker://hashicorp/terraform:1.5.6
with:
entrypoint: terraform
args: -chdir=terraform fmt -check=true -diff=true
terraform-docs-validation:
name: Terraform Docs validation
needs: terraform-validate
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
tflint_version: v0.44.1

- name: Generate Terraform docs
uses: terraform-docs/[email protected]
- name: Run TFLint
working-directory: terraform
run: tflint -f compact

- name: Run TFSec
uses: aquasecurity/[email protected]
with:
working-dir: terraform
config-file: .terraform-docs.yml
output-file: README.md
output-method: inject
fail-on-diff: true
github_token: ${{ github.token }}
23 changes: 0 additions & 23 deletions .github/workflows/continuous-integration-tflint.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/continuous-integration-tfsec.yml

This file was deleted.

0 comments on commit 5b30fe2

Please sign in to comment.