Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #485 from DFE-Digital/ops/ci-terraform
Browse files Browse the repository at this point in the history
Added CI tests for Terraform
  • Loading branch information
DrizzlyOwl authored Jan 11, 2023
2 parents a463b96 + ed5bbe0 commit 4b4621b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/continuous-integration-terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Validate terraform

on:
push:
branches: main
pull_request:

jobs:
terraform-validate:
name: Terraform Validate
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Check for terraform version mismatch
run: |
DOTFILE_VERSION=$(cat terraform.gpaas-azure-migration/.terraform-version)
TERRAFORM_IMAGE_REFERENCES=$(grep "uses: docker://hashicorp/terraform" .github/workflows/continuous-integration-terraform.yml | grep -v TERRAFORM_IMAGE_REFERENCES | wc -l | tr -d ' ')
if [ "$(grep "docker://hashicorp/terraform:${DOTFILE_VERSION}" .github/workflows/continuous-integration-terraform.yml | wc -l | tr -d ' ')" != "$TERRAFORM_IMAGE_REFERENCES" ]
then
echo -e "\033[1;31mError: terraform version in .terraform-version file does not match docker://hashicorp/terraform versions in .github/workflows/continuous-integration-terraform.yml"
exit 1
fi
- name: Remove azure backend
run: rm ./terraform.gpaas-azure-migration/backend.tf

- name: Run a Terraform init
uses: docker://hashicorp/terraform:1.3.6
with:
entrypoint: terraform
args: -chdir=terraform.gpaas-azure-migration init

- name: Run a Terraform validate
uses: docker://hashicorp/terraform:1.3.6
with:
entrypoint: terraform
args: -chdir=terraform.gpaas-azure-migration validate

- name: Run a Terraform format check
uses: docker://hashicorp/terraform:1.3.6
with:
entrypoint: terraform
args: -chdir=terraform.gpaas-azure-migration 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
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Generate Terraform docs
uses: terraform-docs/[email protected]
with:
working-dir: terraform.gpaas-azure-migration
config-file: .terraform-docs.yml
output-file: README.md
output-method: inject
fail-on-diff: true
14 changes: 14 additions & 0 deletions .github/workflows/continuous-integration-tfsec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Terraform security scan
on:
pull_request:
jobs:
tfsec-pr-commenter:
name: tfsec PR commenter
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: tfsec
uses: aquasecurity/[email protected]
with:
github_token: ${{ github.token }}

0 comments on commit 4b4621b

Please sign in to comment.