Add Pytest Service Account to Staging (#3733) #3
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: Terraform Apply | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- 'iac/*' | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
targets: | |
name: Find targets | |
runs-on: ubuntu-latest | |
outputs: | |
staging: ${{ steps.staging.outputs.paths }} | |
production: ${{ steps.production.outputs.paths }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Staging Terraform targets | |
id: staging | |
run: echo "paths=$(find iac -name 'provider.tf' | grep cal-itp-data-infra-staging/ | xargs dirname | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')" >> ${GITHUB_OUTPUT} | |
- name: Production Terraform targets | |
id: production | |
run: echo "paths=$(find iac -name 'provider.tf' | grep cal-itp-data-infra/ | xargs dirname | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')" >> ${GITHUB_OUTPUT} | |
staging: | |
name: Staging | |
needs: targets | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
strategy: | |
fail-fast: false | |
matrix: | |
path: ${{ fromJson(needs.targets.outputs.staging) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: 'google-github-actions/auth@v2' | |
with: | |
create_credentials_file: 'true' | |
project_id: cal-itp-data-infra-staging | |
workload_identity_provider: 'projects/473674835135/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | |
service_account: 'github-actions-terraform@cal-itp-data-infra-staging.iam.gserviceaccount.com' | |
- uses: google-github-actions/setup-gcloud@v2 | |
- name: Terraform Apply | |
uses: dflook/terraform-apply@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
path: ${{ matrix.path }} | |
production: | |
name: Production | |
needs: targets | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
strategy: | |
fail-fast: false | |
matrix: | |
path: ${{ fromJson(needs.targets.outputs.production) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: 'google-github-actions/auth@v2' | |
with: | |
create_credentials_file: 'true' | |
project_id: cal-itp-data-infra | |
workload_identity_provider: 'projects/1005246706141/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | |
service_account: 'github-actions-terraform@cal-itp-data-infra.iam.gserviceaccount.com' | |
- uses: google-github-actions/setup-gcloud@v2 | |
- name: Terraform Apply | |
uses: dflook/terraform-apply@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
path: ${{ matrix.path }} |