Skip to content

Commit

Permalink
Terraform linting CI workflow (#625)
Browse files Browse the repository at this point in the history
* add steps following terraform install instructions

* add tf fmt check step

* add tf init, validate, and comment on PR steps

* add step ids, paths to terraform commands, job run triggers
  • Loading branch information
dpgraham4401 authored Oct 27, 2023
1 parent ed2d7d1 commit af70b20
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/terraform_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: 'Terraform lint'
# This workflow is responsible for running the Haztrak react client tests.

on:
pull_request:
branches:
- main
paths:
- 'infra/**/*.tf'
jobs:
check_terraform_fmt:
name: 'Terraform Format'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./infra/gcp/dev
steps:
- name: 'Checkout'
uses: actions/checkout@v3

- name: 'install terraform dependencies'
run: |
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
- name: 'install hashicorp GPG key'
run: |
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
- name: 'add hashicorp repo'
run: |
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
- name: 'update apt'
run: sudo apt update

- name: 'install terraform'
run: sudo apt-get install terraform

- name: 'Terraform Init'
id: init
run: terraform init -input=false -no-color

- name: 'terraform fmt'
id: fmt
run: terraform fmt -check -recursive ..

- name: 'Terraform Validate'
id: validate
run: terraform validate ..

- name: 'Comment on PR'
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

0 comments on commit af70b20

Please sign in to comment.