Terraform for_each with YAML vars for Queues

Parsing YAML for for_each is messy. The yamldecode function works fine for simple maps, but queues need nested attributes like outbound_calling and wrap_up_timeout_millis. When I pass the decoded map to the resource block, Terraform complains about complex types not being supported in the variable definition.

Here’s the setup:

locals {
 queues_map = yamldecode(file("queues.yaml"))
}

resource "genesyscloud_routing_queue" "this" {
 for_each = local.queues_map
 name = each.value.name
 # How do I handle the nested outbound_calling block here?
}

The YAML structure looks like this:

queue_1:
 name: "Sales A"
 outbound_calling:
 enabled: true

It fails on apply because the provider expects a specific block structure, not a flat map value. I’m stuck trying to map the YAML keys to the required HCL blocks without writing a custom provider or manual resource blocks for every queue. Anyone got a clean pattern for this?

Look, I usually stick to webhook delivery logs and retry policies, but I’ve seen this YAML mess enough times to know it’s a pain. The issue isn’t really yamldecode. It’s that Terraform’s type system chokes when you try to map complex nested objects directly into a for_each without explicit typing. You’re getting those errors because Terraform doesn’t know if outbound_calling is a string, a map, or null until runtime.

You need to define a custom type for your queue config in the variables file. Don’t just pass the raw decoded object. Wrap it in a structure Terraform understands. Here’s how I’ve handled it in my own setups to keep things clean.

variable "queue_configs" {
 type = map(object({
 name = string
 description = string
 wrap_up_timeout_millis = number
 outbound_calling = object({
 enabled = bool
 })
 }))
 default = {}
}

locals {
 # Force the YAML data into the expected type
 typed_queues = { for k, v in var.queue_configs : k => v }
}

resource "genesyscloud_routing_queue" "queues" {
 for_each = local.typed_queues

 name = each.value.name
 description = each.value.description
 wrap_up_timeout_millis = each.value.wrap_up_timeout_millis
 
 outbound_calling {
 enabled = each.value.outbound_calling.enabled
 }
}

In your terraform.tfvars, you’ll still use yamldecode, but you pass it into the variable definition explicitly. This forces Terraform to validate the structure before it hits the resource block. It’s a bit more verbose upfront, but it saves you from those runtime type mismatches. The outbound_calling block needs to be an object, not just a boolean. If you leave it as a flat boolean in the YAML, the type check fails. Make sure your YAML matches the object structure exactly. Also, check that your API user has routing:queue:write scope. Missing scopes often look like type errors in Terraform logs.