Is it possible to dynamically populate variables within a Genesys Cloud Agent Script using the genesyscloud_script resource in Terraform, specifically for conditional logic branches?
Background
We are standardizing our CX deployments across three regions (Sydney, Tokyo, Singapore) using Terraform. The goal is to maintain a single source of truth for Architect flows and Agent Scripts. We have successfully deployed static scripts using the genesyscloud_script resource. However, we now need to implement a script that asks agents to confirm the specific “Region” and “Support Tier” based on the originating queue.
Currently, the script JSON requires hardcoded text for the confirmation step:
resource "genesyscloud_script" "multi_region_script" {
name = "Standard Inquiry Script"
description = "Deployed via Terraform"
# The JSON structure is complex and nested
script_json = jsonencode({
# ... other nodes ...
nodes = [{
id = "node_confirmation"
type = "Text"
text = "Please confirm you are speaking to a Tier 1 agent in the Sydney region."
}]
})
}
Issue
When we attempt to inject Terraform variables into the script_json block using var.region and var.tier, the deployment fails during the genesyscloud_script creation or update phase. The Genesys Cloud API returns a 400 Bad Request with the error message:
{"errors":[{"code":"invalid_request","message":"Script JSON validation failed. Node text content exceeds maximum allowed length or contains invalid characters."}]}
This suggests that the interpolation might be introducing escape characters or formatting issues that the Genesys Cloud scripting engine rejects. The genesyscloud_script documentation mentions that the JSON must be valid and conform to the internal schema, but it does not explicitly state whether dynamic variable injection is supported for content nodes.
Troubleshooting
- Validated JSON Syntax: Used
jqto validate the interpolated JSON locally. It passes standard JSON validation. - Static vs Dynamic: Deployed the exact same JSON with hardcoded strings. It succeeds. This confirms the structure is correct, but the dynamic content is problematic.
- Escape Characters: Attempted to
replace()common escape characters in the Terraform variable before injection. No change in error. - API Directly: Tried updating the script via Postman using the same dynamic JSON. The API accepted it, but the UI showed garbled text or failed to render the conditional branch correctly.
Is there a known limitation with dynamic content in genesyscloud_script? Should we be using a different approach, such as generating the JSON file externally and referencing it via file()? Or is this a bug in the Genesys Cloud Terraform Provider (v1.12.0)?
Looking for insights from others managing large-scale script deployments.