This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
Dev cost optimization (#11) #21
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
name: Lint and validate Development Environment | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "dev/**/*.tf" | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "dev/**/*.tf" | |
jobs: | |
check_fmt: | |
environment: development | |
defaults: | |
run: | |
working-directory: ./dev | |
name: Check Terraform Formatting | |
permissions: | |
contents: read | |
pull-requests: write | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Authenticate Google Cloud | |
uses: google-github-actions/auth@v1 | |
id: auth | |
with: | |
workload_identity_provider: ${{ secrets.WIF_PROVIDER }} | |
service_account: ${{ secrets.SA_EMAIL }} | |
- name: Terraform Init | |
run: terraform init -input=false -no-color | |
- name: Terraform Format | |
run: terraform fmt -check -recursive | |
- name: Terraform 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 | |
}) |