diff --git a/.github/workflows/terraform_lint.yaml b/.github/workflows/terraform_lint.yaml new file mode 100644 index 000000000..d7b263335 --- /dev/null +++ b/.github/workflows/terraform_lint.yaml @@ -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 }}\` +
Validation Output + + \`\`\`\n + ${{ steps.validate.outputs.stdout }} + \`\`\` + +
+ + *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 + })