He given "for_each" argument value is unsuitable: the given "for_each"

I have this code
provider “null” {}

resource “null_resource” “workflow” {
for_each = local.workflow_list
triggers = {
workflow = each.value
environment_type = upper(strrev(substr(strrev(var.environment),0,5)))
json_files = toset((var.environment_type == “QUERY” ? fileset(path.module, “…/…/…/…/workflows/bigquery.json”):
[ for fn in fileset(path.module,join(“”,“…/…/…/…/workflows/”,var.workflow,“.json”)): fn if upper(strrev(substr(strrev(fn),5,5))) != “QUERY”]))

output “js_files” {
value = var.json_files

locals {
workflow_list = toset((var.workflows != null ? split(“;”, var.workflows): null))

module “databricks_workflows” {
for_each = var.json_files
source = “…/…/modules/databricks_workflows”
databricks_workspace_url = var.databricks_workspace_url
databricks_dapi_token = var.databricks_dapi_token
environment = var.environment
prefix = var.prefix
project_name = “DAVE-ADatabricks”
config_path = each.value
cluster_policy_id = var.cluster_policy_id
dlt_cluster_policy_id = var.dlt_cluster_policy_id
dlt_cluster_pool_id = var.dlt_cluster_pool_id
cluster_pool_id = var.cluster_pool_id
providers = {
databricks = databricks.databricks_dev

This error occurs
023-12-06T10:15:32.6710258Z e[0m on main.tf line 36, in module “databricks_workflows”:
2023-12-06T10:15:32.6710876Z 36: for_each = e[4mvar.json_filese[0m
2023-12-06T10:15:32.6711319Z e[0m
2023-12-06T10:15:32.6711685Z The given “for_each” argument value is unsuitable: the given “for_each”
2023-12-06T10:15:32.6712344Z argument value is null. A map, or set of strings is allowed.

Question: how can I tell what type of variable json_files is?

Hi @simon.teff,

The typical answer here would be that you should declare what type var.json_files has as part of its declaration, in the variable "json_files" block.

For example, if you intend to use it as a map of strings:

variable "json_files" {
  type = map(string)

…or, if you intend to use it as a set of strings:

variable "json_files" {
  type = set(string)

Adding a type constraint to your declaration should fix the error you showed, although it will probably be replaced by another error saying that the value assigned to that variable is unsuitable, so you’ll need to keep working upwards until the value being passed is of the expected type.