title: How to iterate through nested list of objects in Terraform
body: <p>I'm creating TF module, which downloads specified yaml files and then uses the yamls as a source for data field in k8s configmaps. I have working solution to create multiple configmaps with one data key-value pair(yaml file), but need also add support for multiple key-value pairs (yaml files) per one configmap.</p>
  <p>main.tf</p>
  <pre><code>data &quot;http&quot; &quot;config-map&quot; {
    for_each = var.cloud-configmap
  
    url = format(&quot;https://%s&quot;, each.value.url)
  
    request_headers = {
      Accept = &quot;text/plain&quot;
    }
  }
  
  resource &quot;kubernetes_config_map&quot; &quot;configmap&quot; {
    for_each = var.cloud-configmap
  
    metadata {
      name = each.value.name
      namespace = each.value.namespace
    }
  
    data = {
      &quot;${each.value.data-keyname}&quot; = data.http.config-map[each.key].body
    }
  }
  </code></pre>
  <p>variables.tf</p>
  <pre><code>variable &quot;cloud-configmap&quot; {
    type = map(object({
      url = string
      name = string
      namespace = string
      data-keyname = string
    }))
    default = {
      &quot;cm1&quot; = {
        url = &quot;someurl.com/file1.yaml&quot;
        name = &quot;cm-name&quot;
        namespace = &quot;test&quot;
        data-keyname = &quot;file1.yml&quot;
      },
      &quot;cm2&quot; = {
        url = &quot;someurl.com/file2.yaml&quot;
        name = &quot;cm-name2&quot;
        namespace = &quot;default&quot;
        data-keyname = &quot;file2.yml&quot;
      }
    }
  }
  </code></pre>
  <p>This code till now is working, but I would like to change the variables.tf file to this:</p>
  <pre><code>variable &quot;cloud-configmap&quot; {
    type = map(object({
      name = string
      namespace = string
      cm-files = list(object({
        url = string
        data-keyname = string 
      }))
    }))
    default = {
      &quot;cm1&quot; = {
        name = &quot;cm-name&quot;
        namespace = &quot;testnamespace&quot;
        cm-files = [{
          url = &quot;someurl.com/file1.yaml&quot;
          data-keyname = &quot;file1.yml&quot;
        },
        {
          url = &quot;someurl.com/file2.yaml&quot;
          data-keyname = &quot;file2.yml&quot;
        }]
      },
      &quot;cm2&quot; = {
        name = &quot;cm-name2&quot;
        namespace = &quot;default&quot;
        cm-files = [{
          url = &quot;someurl.com/file3.yaml&quot;
          data-keyname = &quot;file3.yml&quot;
        },
        {
          url = &quot;someurl.com/file4.yaml&quot;
          data-keyname = &quot;file4.yml&quot;
        }]
      }
    }
  }
  </code></pre>
  <p>And after this change, I don't know how to iterate through the nested list of objects <strong>cm-files</strong> to create configmap with multiple key-value pairs in data field. Any help or pointers would be much appreciated!</p>