I’m trying to automate the creation of several support queues using the Genesys Cloud Terraform provider. We’ve been using a YAML file to store our variable data, and I want to use for_each to iterate over the queue definitions in that file. The goal is to keep the IaC clean and separate the config data.
Here is the relevant snippet from my main.tf:
data "external" "queue_vars" {
program = ["python", "scripts/parse_queues.py"]
}
resource "genesyscloud_routing_queue" "support_queues" {
for_each = jsondecode(data.external.queue_vars.result)
name = each.value.name
description = each.value.description
enabled = true
}
The Python script outputs a JSON object where keys are queue IDs and values are objects with name and description. When I run terraform plan, it crashes with this error:
`Error: Invalid for_each argument
on main.tf line 4, in resource “genesyscloud_routing_queue” “support_queues”:
4: for_each = jsondecode(data.external.queue_vars.result)
The given “for_each” argument value is unsuitable: the attribute “result” is an object with no known elements. To work with for_each, its elements must be known exactly.`
I’ve verified the Python script output is valid JSON. I tried changing the data source to return a map directly, but Terraform still complains about the type during the plan phase. It seems like jsondecode doesn’t play nice with external data sources that are evaluated at apply time or something similar.
I also tried using toml instead of YAML, but the parsing logic got messy. Is there a standard pattern for loading a list of objects from an external file into a for_each loop for Genesys resources? I don’t want to hardcode the queue names in the TF file.
Any ideas on how to force the type resolution here? I’ve checked the docs but they mostly show static maps.