Terraform for_each with YAML queues: variable interpolation fails

Stuck on defining multiple Genesys Cloud queues from a YAML variable file using for_each in the Terraform CXone provider. I want to avoid hardcoding resources, so I’m loading a YAML map into Terraform via a custom data source and iterating over it. The plan crashes immediately with a type mismatch error.

  1. Load YAML config into local.queue_config using yamldecode(file("queues.yaml")).
  2. Define resource genesys_cloud_queue with for_each = local.queue_config.
  3. Set name = each.value.name and description = each.value.description.

Here is the snippet causing the issue:

resource "genesys_cloud_queue" "supervisor_queues" {
 for_each = local.queue_config
 name = each.value.name
 description = each.value.description
}

Error output:

Error: Invalid for_each argument

on main.tf line 12:
 12: for_each = local.queue_config

A "for_each" value is not supported on resources.

I’ve verified the YAML structure is a flat map of objects. Is the CXone provider blocking dynamic iteration for queue resources specifically, or is this a fundamental Terraform limitation I’m missing? I’m on TF 1.5.0 and provider v1.2.3.

I think the YAML decoder returns a generic map, which often breaks for_each type inference in Terraform when nested objects are present. The provider expects explicit attribute definitions, not raw maps.

Cause:
The genesys_cloud_queue resource requires specific types (string, bool) for attributes like name and description. Passing a raw map from yamldecode results in a type mismatch during the plan phase because Terraform cannot guarantee the schema matches the resource definition.

Solution:
Wrap the YAML data in a local map with explicit type casting. This ensures for_each receives a predictable structure.

locals {
 queues = { for k, v in yamldecode(file("queues.yaml")) : k => {
 name = tostring(v.name)
 description = tostring(v.description)
 enabled = tobool(v.enabled)
 } }
}

resource "genesys_cloud_queue" "dynamic_queues" {
 for_each = local.queues

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

This pattern mirrors how we handle complex config objects in the Web Messaging SDK, ensuring type safety before initialization. Always validate the YAML keys against the provider schema to avoid silent failures.

This has the hallmarks of a standard type coercion issue where yamldecode returns a generic map that Terraform cannot statically analyze for for_each. You need to explicitly cast the decoded map to a specific structure using toset or a local variable with defined types before passing it to the resource block.