Need some help troubleshooting the terraform import command for an existing IVR. I am trying to wrap my GC REST APIs in a unified GraphQL gateway, but the Terraform state import is failing with a 422 Unprocessable Entity error.
terraform import genesyscloud_ivr.my_ivr <ivr-id>
Error: Provider returned inconsistent result after apply
The resource exists in GC, and I have verified the ID via the /api/v2/flows endpoint. The state file remains empty. Is this a known issue with the provider’s import logic for complex flow definitions?
Thanks for the help.
Have you tried verifying the exact structure of the IVR definition before importing? The 422 error during terraform import usually means the provider cannot map the existing resource’s complex nested attributes to the schema, specifically around flow conditions or prompt definitions. You need to fetch the raw JSON via the API first to ensure all optional fields are present or explicitly null. Use the endpoint /api/v2/flows/ivr/{ivrId} with a GET request. If the response contains malformed JSON or missing required fields like name or description, Terraform will fail to reconcile the state. Check your IAM permissions too; import:ivr scope is mandatory. I usually write a quick Node.js script using the PureCloudPlatformClientV2 SDK to validate the resource exists and is readable before running terraform import. This avoids the black box error. Ensure your Terraform version is latest, as older versions had bugs with complex IVR structures.
The quickest way to solve this is… you’ll need to sanitize the raw JSON before feeding it to Terraform. The provider chokes on complex nested structures like flowConditions or promptDefinitions. I run a quick n8n workflow to fetch /api/v2/flows/ivr/{ivrId} and strip out any nulls or empty arrays that cause schema mismatches.
curl -H "Authorization: Bearer <token>" "https://api.mypurecloud.com/api/v2/flows/ivr/{ivrId}" | jq 'del(.flowConditions[] | select(.condition == null))' > sanitized_ivr.json
Import using that cleaned file. It’s a pain, but it works.
The quickest way to solve this is to strip the flowConditions array before import. I use ToString in a Data Action to clean the payload: ToString(FindFirst(data.conditions, "id", "null")). It stops the provider from choking on nested nulls.