Skip to content

Merge pull request #78 from kevinsunny1996/build/add_bq_data_viewer #145

Merge pull request #78 from kevinsunny1996/build/add_bq_data_viewer

Merge pull request #78 from kevinsunny1996/build/add_bq_data_viewer #145

Workflow file for this run

name: Terraform GCP Pipeline
on:
push:
branches:
- "main"
paths:
- 'terraform/**'
- '.github/workflows/terraform.yaml'
pull_request:
branches:
- "main"
paths:
- 'terraform/**'
- '.github/workflows/terraform.yaml'
jobs:
terraform:
permissions:
contents: 'read'
id-token: 'write'
pull-requests: 'write' #Needed to comment on the PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: 'plannerAuth'
if: github.ref != 'refs/heads/main'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/221017926326/locations/global/workloadIdentityPools/github/providers/github'
service_account: '[email protected]'
- id: 'applierAuth'
if: github.ref == 'refs/heads/main'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/221017926326/locations/global/workloadIdentityPools/github/providers/github'
service_account: '[email protected]'
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.4.5
- id: fmt
name: Terraform fmt
working-directory: terraform
run: terraform fmt -check
- id: init
name: Terraform Init
working-directory: terraform
run: terraform init -input=false -backend-config="bucket=tf-state-tracker"
# - id: validate
# name: Terraform Validate
# run: terraform validate -no-color
- id: plan
name: Terraform Plan
working-directory: terraform
run: terraform plan -var='project_number=${{secrets.GCP_PROJECT_NUMBER}}' -var='project_id=${{secrets.GCP_PROJECT_ID}}' -no-color
continue-on-error: true
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
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 }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
working-directory: terraform
run: terraform apply -var='project_number=${{secrets.GCP_PROJECT_NUMBER}}' -var='project_id=${{secrets.GCP_PROJECT_ID}}' -auto-approve -input=false