Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform linting CI workflow #625

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
Loading