Terraform for_each with YAML queue definitions

Trying to map a YAML list of queue configs to for_each in the Genesys Cloud provider. The YAML parses fine into a map, but the resource block complains about attribute types. I’ve got queues.yaml with names and descriptions.

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

resource "genesyscloud_routing_queue" "this" {
 for_each = local.queues
 name = each.value.name
}

Hitting a validation error on name. How do you structure the YAML so the provider accepts it without manual map conversion?

Docs state: “The yamldecode function parses YAML content into a map or list structure.” You’re likely missing the actual parsing step. file() just returns a string. Terraform doesn’t magically know YAML.

Here is the working pattern for mapping YAML to for_each.

locals {
 # Parse the YAML file into a map structure
 raw_queues = yamldecode(file("queues.yaml"))
 
 # Convert to a map keyed by name or ID for for_each
 # Assuming your YAML is a list of objects
 queues_map = { for q in local.raw_queues : q.name => q }
}

resource "genesyscloud_routing_queue" "this" {
 for_each = local.queues_map

 name = each.key
 description = each.value.description
 enabled = true
}

Your YAML should look like this:

- name: "Support Tier 1"
 description: "First line support"
- name: "Support Tier 2"
 description: "Escalation queue"

The error on name happens because local.queues was a string, not a map. for_each expects a map or set. If you use yamldecode on a map directly in YAML (key: value pairs), you can skip the for expression.

Support Tier 1:
 description: "First line support"

Then local.queues = yamldecode(file("queues.yaml")) works directly with for_each.

Check the genesyscloud_routing_queue resource docs. It requires name to be a string. If your YAML has nested objects, you need to flatten them or use the correct key.

Also, don’t forget division_id if you’re not using the default. Missing that causes silent failures or wrong placement.

resource "genesyscloud_routing_queue" "this" {
 for_each = local.queues_map
 name = each.key
 division_id = var.default_division_id
}

Run terraform validate after fixing the parse step. It usually catches the type mismatch.