I’m trying to set up a CI/CD pipeline using GitHub Actions to manage our Genesys Cloud resources via the genesyscloud Terraform provider. The goal is straightforward: run terraform plan on every pull request to catch drift, and only run terraform apply when the PR merges to main. I’ve got the OIDC workflow configured for authentication, so no static tokens are floating around. That part works fine.
The issue pops up during the plan phase. When I push a change to a feature branch, the action triggers and runs terraform init and terraform plan. It immediately throws a 409 Conflict error on resources that already exist in the org. The error message says something like “Resource with id ‘abc-123’ already exists.” I know the resource exists. That’s the point. The plan should detect the difference between the state file and the live environment, not fail outright because the resource is there.
Here’s the relevant snippet from my ci.yml:
- name: Terraform Plan
run: |
terraform plan -out=tfplan
I’m using a remote backend with S3 for state storage. The state file is definitely present because terraform init pulls it down. I’ve checked the state file manually, and it contains the correct IDs for the existing routing queues. I suspect the provider is trying to create the resource instead of reading it during the plan step, or maybe the import block isn’t being respected in the plan phase.
I’ve tried adding import blocks to the code, but that feels like a hack for a CI pipeline. Should I be using terraform import in a separate step before the plan? Or is there a flag I’m missing in the plan command to handle existing resources gracefully? The docs mention terraform plan -refresh=false but that doesn’t seem to help with the ID conflict.
I’m stuck on why the plan phase is treating existing resources as if they need to be created, causing the API call to fail with a 409. Any ideas on how to structure the workflow so the plan step just compares state without trying to write to the API?