0
votes

I have the following terraform:

The idea is that I can pass in volumes and either pass binary_data or data and this module will handle accordingly.

However it is not liking the nested loop. I have a feeling it's not liking iterating on the object.

When I run this I get the following error

#variable.tf
variable "volumes" {
  type        = map(object({
    data = map(string)
    binary_data = map(string)
  }))
  description = "configmap backed volume"
}
#main.tf
resource "kubernetes_config_map" "volume" {
  for_each = var.volumes

  metadata {
    name = each.key
    namespace = var.namespace
  }

  dynamic "data" {
    for_each = each.value["data"]

    content {
      each.key = each.value
    }
  }

  dynamic "binary_data" {
    for_each = each.value["binary_data"]
    content {
      each.key = each.value
    }
  }
 }

Error: Argument or block definition required

On ../../../terraform-modules/helm_install/main.tf line 45: An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

1

1 Answers

0
votes

data and binary_data are arguments, not blocks. dynamic blocks apply only to blocks, not to arguments.

This means that you can't create multiple data and binary_data in a single kubernetes_config_map. You would have to apply for_each at the resource level:

resource "kubernetes_config_map" "volume" {

  for_each = var.volumes

  metadata {
    name = each.key
    namespace = var.namespace
  }

  data        = each.value["data"]
  binary_data = each.value["binary_data"]

}

I haven't verified the above code, thus threat it as an example only.