Can anyone clarify why for_each throws a type mismatch when iterating over a map generated from a YAML file to create genesyscloud_routing_queue resources? I am using Terraform v1.7.5 with the genesyscloud provider v1.25.0. My goal is to externalize queue definitions into a YAML file for easier maintenance by non-devops staff, then import that structure into Terraform.
Here is my queues.yaml:
queue_map:
sales_us:
name: "US Sales"
description: "US Sales Queue"
support_uk:
name: "UK Support"
description: "UK Support Queue"
I load this using file and yamldecode:
locals {
raw_yaml = yamldecode(file("${path.module}/queues.yaml"))
queue_map = local.raw_yaml.queue_map
}
Then I attempt to create the resources:
resource "genesyscloud_routing_queue" "dynamic_queues" {
for_each = local.queue_map
name = each.value.name
description = each.value.description
acd_strategy = "LONGEST_IDLE_AGENT"
}
The plan fails with:
Error: Invalid for_each argument on main.tf line 10: for_each = local.queue_map This map contains elements with key "sales_us" that have a value of type object, but for_each requires a map of strings or a set of strings.
I understand for_each expects a map of strings or a set. The values in my YAML are objects. I tried converting the keys to a set using keys(local.queue_map) and then accessing the values via local.queue_map[each.key].name, but that feels redundant and loses the direct mapping benefit. Is there a cleaner way to flatten or transform this YAML structure into a format for_each accepts without writing complex local maps? Or am I missing a provider-specific pattern for bulk resource creation from external configs?