Running into a type mismatch error when trying to use for_each to create multiple queues based on a YAML variable file. Here is the setup:
variable "queues" {
type = any
default = yamldecode(file("queues.yaml"))
}
resource "genesyscloud_routing_queue" "main" {
for_each = var.queues
name = each.value.name
description = each.value.desc
}
The YAML file looks like this:
- name: "Support US"
desc: "US Support Queue"
- name: "Support EU"
desc: "EU Support Queue"
Terraform plan fails with:
Error: Invalid for_each argument on main.tf line 5: 5: for_each = var.queues Each value in for_each maps to an instance, determined by the key of each element. The given map is of type tuple. A map must have string keys to be used with for_each.
I’ve tried wrapping the variable in tojson() and fromjson() but that just turns it into a single string which breaks the iteration. I also tried using for to convert the tuple to a map like { for q in var.queues : q.name => q } but the provider seems to choke on the nested object structure when applying. The error shifts to something about invalid attribute types on the queue resource itself.
Is there a standard pattern for handling list-based YAML inputs with for_each in the Genesys Cloud provider? I’m used to doing this in Python scripts where I can just iterate over the list directly, but Terraform’s strict typing on for_each is getting in the way. The docs say for_each expects a map or set of strings, so passing a list of objects feels wrong. I’ve checked the provider issues on GitHub but most examples use static maps defined inline.
Any ideas on how to transform this YAML list into a format the provider accepts without losing the nested attributes? I need to keep the YAML as the source of truth for our dev team since they prefer editing YAML over HCL maps.