-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terraform linting CI workflow (#625)
* 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
1 parent
ed2d7d1
commit af70b20
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |