Trying to run terraform plan on every PR for our CXone org. Getting a state lock error when the pipeline tries to read the remote state on S3.
Here is the github action step:
- name: Plan
run: terraform init && terraform plan -out=tfplan
It works locally but fails in CI with Acquiring the state lock... Error acquiring the state lock. We are using the nicecxone provider. How do we handle state locking in a parallel CI environment?
State locks usually happen when a previous run didn’t clean up properly. If a local terraform plan or an earlier CI job crashed, the lock file might still be sitting in that S3 bucket holding up the new request.
First, check the lock info to see who (or what) is holding it.
terraform force-unlock <LOCK_ID>
You can find that ID in the error output. It’s a UUID string. Run that command locally with the same backend config. If it clears, your pipeline should pick up right where it left off.
If you’re seeing this frequently in CI, you might want to add a retry step or ensure your jobs are serializing access to that specific state file. Parallel plans on the same state without dynamic locking support will always collide. The nicecxone provider doesn’t handle the S3 lock itself, so Terraform’s native backend logic is what you’re fighting here. Just make sure your GitHub Actions workflow has the right permissions to write to that bucket too.