Skip to content

Commit

Permalink
Merge pull request #55 from DFE-Digital/initial-terraform
Browse files Browse the repository at this point in the history
Added initial terraform
  • Loading branch information
DrizzlyOwl authored Jan 27, 2025
2 parents 96810b0 + 4a4b3b2 commit a39386b
Show file tree
Hide file tree
Showing 16 changed files with 911 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Continuous Integration / Terraform

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

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

- name: Check for terraform version mismatch
run: |
DOTFILE_VERSION=$(cat terraform/.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: 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.9.8
with:
entrypoint: terraform
args: -chdir=terraform init

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

- name: Run a Terraform format check
uses: docker://hashicorp/terraform:1.9.8
with:
entrypoint: terraform
args: -chdir=terraform fmt -check=true -diff=true

- name: Setup TFLint
uses: terraform-linters/setup-tflint@v4
with:
tflint_version: v0.44.1

- name: Run TFLint
working-directory: terraform
run: tflint -f compact

- name: Run TFSec
uses: aquasecurity/[email protected]
with:
github_token: ${{ github.token }}
26 changes: 26 additions & 0 deletions terraform/.terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
formatter: "markdown table"
version: "~> 0.16"
settings:
anchor: true
default: true
description: false
escape: true
hide-empty: false
html: true
indent: 2
lockfile: true
read-comments: true
required: true
sensitive: true
type: true
sort:
enabled: true
by: name
output:
file: README.md
mode: inject
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
1 change: 1 addition & 0 deletions terraform/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.8
125 changes: 125 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions terraform/Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
brew "tfenv"
brew "terraform-docs"
brew "tfsec"
brew "az"
brew "coreutils"
brew "jq"
Loading

0 comments on commit a39386b

Please sign in to comment.