Hey folks,
I’m trying to get our Terraform workflow set up properly for the Genesys Cloud provider. We want a standard CI/CD flow where terraform plan runs automatically when a PR is opened, and terraform apply triggers only after the PR is merged into main.
The tricky part is handling the OAuth credentials securely in the pipeline environment without hardcoding them. I’ve been using environment variables for the GENESYS_CLOUD_OAUTH_CLIENT_ID and GENESYS_CLOUD_OAUTH_CLIENT_SECRET, but I’m running into issues with the token expiration during long-running plans.
Here’s the basic structure of my GitHub Actions workflow:
name: Terraform CI/CD
on:
pull_request:
paths:
- '.github/workflows/terraform.yml'
- 'terraform/**'
push:
branches:
- main
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Terraform Init
run: terraform init
- name: Terraform Plan
if: github.event_name == 'pull_request'
run: terraform plan -out=tfplan
env:
GENESYS_CLOUD_OAUTH_CLIENT_ID: ${{ secrets.GENESYS_CLIENT_ID }}
GENESYS_CLOUD_OAUTH_CLIENT_SECRET: ${{ secrets.GENESYS_CLIENT_SECRET }}
GENESYS_CLOUD_OAUTH_GRANT_TYPE: client_credentials
GENESYS_CLOUD_OAUTH_JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
- name: Terraform Apply
if: github.ref == 'refs/heads/main'
run: terraform apply -auto-approve tfplan
env:
GENESYS_CLOUD_OAUTH_CLIENT_ID: ${{ secrets.GENESYS_CLIENT_ID }}
GENESYS_CLOUD_OAUTH_CLIENT_SECRET: ${{ secrets.GENESYS_CLIENT_SECRET }}
GENESYS_CLOUD_OAUTH_GRANT_TYPE: client_credentials
GENESYS_CLOUD_OAUTH_JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
The plan step works fine on the PR, but when I try to apply on merge, it fails because the state file isn’t persisted between the PR check and the merge action. I’m storing state in a local backend for now, which obviously doesn’t work across different workflow runs.
Should I be using a remote backend like S3 or Terraform Cloud? And how do I handle the state locking so two people don’t apply at the same time? Also, is there a way to cache the OAuth token between steps so it doesn’t time out?
Any advice on setting up the remote state backend securely?