Enable/disable resource in terraform using count I added a piece of code to support enable/disable to the feature - I used the count. Now I have the following problem:
ERROR:
on modules/eventhub/main.tf line 110, in resource &quot;azurerm_eventhub&quot; &quot;events&quot;:

 110:   namespace_name      = azurerm_eventhub_namespace.eventhub.*.name
    |----------------
    | azurerm_eventhub_namespace.eventhub is tuple with 1 element

Inappropriate value for attribute &quot;namespace_name&quot;: string required.

# Create EventHub namespace
resource &quot;azurerm_eventhub_namespace&quot; &quot;eventhub&quot; {
  count               = var.enable_eh ? 1 : 0
  name                  = &quot;${var.name}-ns&quot;
  location              = var.location
  resource_group_name   = var.resource_group
  sku                   = var.sku
  capacity              = var.capacity
  dedicated_cluster_id = azurerm_eventhub_cluster.eventhub[count.index].id #for eventHub Cluster
  auto_inflate_enabled     = var.auto_inflate != null ? var.auto_inflate.enabled : null
  maximum_throughput_units = var.auto_inflate != null ? var.auto_inflate.maximum_throughput_units : null

    dynamic &quot;network_rulesets&quot; {
    for_each = var.network_rules != null ? [&quot;true&quot;] : []
    content {
      default_action = &quot;Deny&quot;
      dynamic &quot;ip_rule&quot; {
        for_each = var.network_rules.ip_rules
        iterator = iprule
        content {
          ip_mask = iprule.value
        }
      }

      dynamic &quot;virtual_network_rule&quot; {
        for_each = var.network_rules.subnet_ids
        iterator = subnet
        content {
          subnet_id = subnet.value
        }
      }
    }
  }

  tags = var.tags
}

resource &quot;azurerm_eventhub_namespace_authorization_rule&quot; &quot;events&quot; {
  for_each            = local.authorization_rules
  name                = each.key
  namespace_name      = azurerm_eventhub_namespace.eventhub.*.name
  resource_group_name = var.resource_group

  listen = each.value.listen
  send   = each.value.send
  manage = each.value.manage

}

resource &quot;azurerm_eventhub&quot; &quot;events&quot; {
  for_each            = local.hubs
  name                = each.key
  **namespace_name      = azurerm_eventhub_namespace.eventhub.*.name  &lt;------ problematic line**

  resource_group_name = var.resource_group
  partition_count     = each.value.partitions
  message_retention   = each.value.message_retention

}

I don't know what the issue is.
I believe you should be able to reference the namespace name like so:
namespace_name      = azurerm_eventhub_namespace.eventhub[0].name
However, if the namespace_name field is a required parameter on the resources you are passing it to, you might run into other issues while you are trying to set enabled to false, as the resources depend on the output of the resource you are setting to count[0]. If you want them all to be conditional on the creation of the namespace, i would recommend continuing down your approach with the for_each over the local values.
If you need to the other resources to not be created unless the namespace is created you can create a condition on your local value like this (assuming map):
locals{
    hub = var.enable_eh ? {foo = &quot;bar&quot;, baz = &quot;qux&quot;} : {}
}

The for_each will omit the resources that are empty.