I’m trying to automate queue creation using the Genesys Cloud Terraform provider and a YAML file for input. The goal is to read a list of queue configs from queues.yaml and use for_each to create them.
Here is the data source setup:
data "external" "queue_config" {
program = ["node", "yaml_parser.js"]
}
The parser outputs JSON that looks like this:
{
"values": {
"sales_team": {
"name": "Sales Team",
"description": "Main sales queue"
},
"support_team": {
"name": "Support Team",
"description": "Main support queue"
}
}
}
Then I’m trying to use it in the resource:
resource "genesyscloud_routing_queue" "queues" {
for_each = data.external.queue_config.result.values
name = each.value.name
description = each.value.description
}
Terraform plan fails with:
Error: Invalid for_each argument
on main.tf line 5, in resource “genesyscloud_routing_queue” “queues”:
for_each = data.external.queue_config.result.valuesA map or set of objects must be used with for_each.
I’ve checked the docs. The external data source returns a map of strings to complex objects. The error says it needs a map or set of objects. It seems like it’s treating the values as strings or something else.
I’ve tried converting it to a map using jsondecode but that just gives me a list of objects, not a map keyed by the queue ID.
Is there a way to force the external data source to return a proper map of objects? Or do I need to use a local variable to transform the output before passing it to for_each?
I’m using Terraform 1.5.7 and the latest Genesys Cloud provider. The YAML file is simple, no nested lists, just flat maps of queue properties.
Any ideas on how to structure the external data source output to make for_each happy?