Stuck on genesyscloud_screen_recording_policy state sync. Provider 1.65.2 throws 409 Conflict on apply. The API returns “Resource already exists” despite no prior resource in state. Sydney region. Any workaround for idempotent creation?
Cause: the provider tries to create the resource even if it exists in the api but is missing from state. this usually happens after a manual deletion or a state import error. the api throws 409 because the name is unique.
Solution: use import to bring it back into state instead of recreating.
# terraform.tfstate fix
resource "genesyscloud_screen_recording_policy" "my_policy" {
name = "my_policy"
# ... other config
}
run this in terminal:
terraform import genesyscloud_screen_recording_policy.my_policy <resource_id>
if you don’t have the id, check the api directly with java sdk or curl. once it’s in state, apply won’t throw 409.
yeah, terraform import is the way to go. just need the id from the api first.
curl -H "Authorization: Bearer $TOKEN" \
"https://api.us-east-1.my.genesys.cloud/api/v2/screenpolicies" | jq '.entities[0].id'
then run terraform import genesyscloud_screen_recording_policy.my_policy <id>
yeah, the import fix is solid but don’t forget to handle the conflicts attribute if you’re managing multiple policies. the provider gets tripped up if the name matches an existing resource that wasn’t imported correctly. also, check your scope. you need screenpolicies:view and screenpolicies:write.
here’s a quick check to ensure the policy actually exists before you try to import or create. saves a headache if the api returns empty.
curl -X GET "https://api.us-east-1.my.genesys.cloud/api/v2/screenpolicies" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq '.entities[] | select(.name == "my_policy") | .id'
if that returns null, the resource is gone. if it returns an id, use that for the import. the 409 is just the api screaming that the name is taken. terraform doesn’t always see what the api sees until you force the sync. just make sure your state file is clean before running terraform plan again. i’ve seen it drift twice now. annoying but fixable.
honestly, terraform state drift is a pain. but if you’re already pulling analytics, just query the api directly. ignore the provider noise.
- get the id via curl.
- import it.
don’t fight the 409. just sync the state.