Terraform GC Provider: Plan on PR, Apply on Merge - State Locking Issues

Setting up a CI/CD pipeline for Genesys Cloud resources using the Terraform provider. The goal is straightforward: run terraform plan on every pull request and terraform apply only on merge to main. Using GitHub Actions with a remote backend on S3 with DynamoDB for state locking.

The plan step works fine. It generates the diff and comments it on the PR. The problem is the apply step. When the PR merges, the workflow triggers, fetches the state, and tries to apply. It fails immediately with a state locking error:

Error acquiring the state lock.
Lock Info:
 ID: abc-123-def
 Path: gc-state/terraform.tfstate
 Operation: OperationTypeApply
 Who: runner@github-host
 Version: 1.6.0
 Created: 2023-10-27 14:30:00 +0000 UTC
 Info: ...

The lock isn’t being released. I’ve verified the DynamoDB table is correct and permissions are fine. The plan step releases its lock correctly. But the apply step, which runs in a separate job context after merge, seems to hit a stale lock or the previous lock isn’t clearing as expected.

Is there a specific way to handle state locking in the Genesys Cloud Terraform provider for CI/CD? Or is this a standard Terraform issue I’m missing? The provider docs don’t mention CI/CD state management specifics.

Current workflow snippet:

plan:
 runs-on: ubuntu-latest
 steps:
 - uses: actions/checkout@v3
 - uses: hashicorp/setup-terraform@v2
 - run: terraform init
 - run: terraform plan -out=tfplan

apply:
 needs: plan
 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
 runs-on: ubuntu-latest
 steps:
 - uses: actions/checkout@v3
 - uses: hashicorp/setup-terraform@v2
 - run: terraform init
 - run: terraform apply -auto-approve tfplan

The apply job fails on terraform apply. The plan file from the PR isn’t available in the merge context obviously. So I’m running a fresh apply. But the state lock persists.

Anyone have a working example for GC resources? The provider is relatively new compared to AWS or GCP. Might be missing some nuance in how it handles concurrent access or state file metadata.

Lagos time is 3 AM. Brain is foggy. Need a hint before coffee.