Skip to content

Merge pull request #6 from KlubJagiellonski/feature/add-sql #18

Merge pull request #6 from KlubJagiellonski/feature/add-sql

Merge pull request #6 from KlubJagiellonski/feature/add-sql #18

Workflow file for this run

name: Terraform
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
env:
TF_VERSION: "1.14.0"
WORKLOAD_IDENTITY_POOL: "github-actions-pool"
WORKLOAD_IDENTITY_PROVIDER: "github-actions-provider"
jobs:
terraform:
name: Terraform - ${{ matrix.stack }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
strategy:
fail-fast: false
matrix:
include:
- stack: stacks/projects/kj-pola-web-stg
gcp_project_id: kj-pola-web-stg
gcp_project_number: "345026739965"
- stack: stacks/projects/kj-pola-web-prod
gcp_project_id: kj-pola-web-prod
gcp_project_number: "288124577198"
- stack: stacks/projects/kj-pola-backend-stg
gcp_project_id: kj-pola-backend-stg
gcp_project_number: "901165314592"
- stack: stacks/projects/kj-pola-backend-prod
gcp_project_id: kj-pola-backend-prod
gcp_project_number: "306379713727"
- stack: stacks/projects/kj-pola-shared-prod
gcp_project_id: kj-pola-shared-prod
gcp_project_number: "802307596796"
# - stack: stacks/projects/pola-analytics-prod
# gcp_project_id: psychic-mason-449108-u3
# gcp_project_number: "248326328298"
# - stack: stacks/projects/pola-bi-looker
# gcp_project_id: pola-bi-looker
# gcp_project_number: "354540873199"
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093
with:
workload_identity_provider: projects/${{ matrix.gcp_project_number }}/locations/global/workloadIdentityPools/${{ env.WORKLOAD_IDENTITY_POOL }}/providers/${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: terraform-runner@${{ matrix.gcp_project_id }}.iam.gserviceaccount.com
- name: Set up Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Terraform Format Check
id: fmt
run: terraform fmt -check -recursive
continue-on-error: true
working-directory: ${{ matrix.stack }}
- name: Run Checkov with Reviewdog
id: checkov
uses: fulgas/reviewdog-action-checkov@8238124bf7d3262e05abcdd844ddf8f2fc4a0d3d # v2.3.0
if: github.event_name == 'pull_request'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
work_dir: ${{ matrix.stack }}
reporter: github-pr-review
continue-on-error: true
- name: Terraform Init
id: init
run: terraform init -input=false
working-directory: ${{ matrix.stack }}
- name: Terraform Validate
id: validate
run: terraform validate -no-color
working-directory: ${{ matrix.stack }}
- name: Terraform Plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
working-directory: ${{ matrix.stack }}
continue-on-error: true
- name: Comment PR
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const getIcon = (outcome) => {
if (outcome === 'success') return '✅';
if (outcome === 'failure') return '❌';
if (outcome === 'cancelled') return '⚠️';
return '⏭️';
};
const fmtOutcome = '${{ steps.fmt.outcome }}';
const checkovOutcome = '${{ steps.checkov.outcome }}';
const initOutcome = '${{ steps.init.outcome }}';
const validateOutcome = '${{ steps.validate.outcome }}';
const planOutcome = '${{ steps.plan.outcome }}';
const output = `### Project: ${{ matrix.gcp_project_id }}
#### Terraform Format and Style 🖌 ${getIcon(fmtOutcome)}
#### Checkov Security Scan 🔒 ${getIcon(checkovOutcome)}
#### Terraform Initialization ⚙️ ${getIcon(initOutcome)}
#### Terraform Validation 🤖 ${getIcon(validateOutcome)}
#### Terraform Plan 📖 ${getIcon(planOutcome)}
<details><summary>Show Plan</summary>
\`\`\`
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ matrix.stack }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false
working-directory: ${{ matrix.stack }}