Hey folks,
I’m trying to automate the creation of about 50 support queues in Genesys Cloud using Terraform. Instead of hardcoding resources, I wanted to use a YAML file to define the queue configurations and then iterate over them with for_each. The goal is to keep the infrastructure code clean and let the ops team update the YAML without touching the .tf files.
Here’s the setup. I’m using the yamldecode function to parse the file.
locals {
queue_data = yamldecode(file("${path.module}/queues.yaml"))
}
The YAML structure looks like this:
queue_a:
name: "Team A Support"
description: "General inquiries"
queue_b:
name: "Team B Sales"
description: "New leads"
Then I’m defining the resource like this:
resource "genesyscloud_routing_queue" "queues" {
for_each = local.queue_data
name = each.value.name
description = each.value.description
}
When I run terraform plan, it throws an error:
`Error: Invalid index
on main.tf line 10, in resource “genesyscloud_routing_queue” “queues”:
10: for_each = local.queue_data
A map or set of objects is required.`
I’m confused because yamldecode should return a map. I’ve checked the output of local.queue_data in a debug log, and it looks like a proper map of objects. But Terraform seems to treat it as something else. I’ve tried casting it explicitly with local.queue_data but that didn’t help.
Is there a specific way the Genesys Cloud provider expects the map to be structured? Or am I missing something basic with how for_each handles YAML maps in this version of the provider?
Also, if I use a list instead of a map, I lose the ability to reference the queues by their logical key name later in the code, which I need for setting up routing rules. So I really need for_each to work here.
Any pointers?