title: alternative way, since for_each and count cannot be in same resource
body: <p>I've config that need to use count and for_each at the same time.
  here's the config block</p>
  <pre><code>variable &quot;all_zone&quot; {
    type    = list(any)
    default = [&quot;asia-southeast1-a&quot;, &quot;asia-southeast1-b&quot;, &quot;asia-southeast1-c&quot;]
  }
  
  variable &quot;backends&quot; {
    description = &quot;Map backend indices to list of backend maps.&quot;
    type = map(object({
      neg_name  = string
     }))
  }
  
  data &quot;google_compute_network_endpoint_group&quot; &quot;get_neg&quot; {
    for_each = var.backends
    count   = length(var.all_zone)
    zone    = var.all_zone[count.index]
    name    = lookup(each.value, &quot;neg_name&quot;)
    
  }
  
  resource &quot;google_compute_backend_service&quot; &quot;default&quot; {
  . . .
  dynamic &quot;backend&quot; {
      for_each = [for b in data.google_compute_network_endpoint_group.get_neg[*].id : b]
      content {
        group = backend.value
      }
    }
  }
  </code></pre>
  <p>is there anyway to do this?</p>
  <p>Update: here's sample var.backends</p>
  <pre><code>backends = {
      default = {
          neg_name = 'name-1'
      }
  }
  </code></pre>
  <p><strong>Update: Thanks for @marcin for the solution. but I've another problem to acessing this data.</strong></p>
  <p>Before I use <code>helper_map</code></p>
  <pre><code>
  data &quot;google_compute_network_endpoint_group&quot; &quot;get_neg&quot; {
    count   = length(var.all_zone)
    zone    = var.all_zone[count.index]
    name    = 'name-1'
    
  }
  
  </code></pre>
  <p>and here structure off the output data:</p>
  <pre><code>neg = [
        + {
            + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-a/networkEndpointGroups/name-1&quot;
            + name                  = &quot;name-1&quot;
            + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-a&quot;
          },
        + {
            + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-b/networkEndpointGroups/name-1&quot;
            + name                  = &quot;name-1&quot;
            + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-b&quot;
          },
        + {
            + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-c/networkEndpointGroups/name-1&quot;
            + name                  = &quot;name-1&quot;
            + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-c&quot;
          },
      ]
  </code></pre>
  <p>here's I accessing the data</p>
  <pre><code>for_each = [for b in data.google_compute_network_endpoint_group.get_neg[*].id : b]
  </code></pre>
  <p>after use <code>map_helper</code></p>
  <pre><code>neg = [
        + {
            + default-asia-southeast1-a  = {
                + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-a/networkEndpointGroups/k8s1-e051d246-default-gclb-poc-8080-ef51ff1c&quot;
                + name                  = &quot;name-1&quot;
                + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-a&quot;
              }
            + default-asia-southeast1-b  = {
                + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-b/networkEndpointGroups/name-1&quot;
                + name                  = &quot;name-1&quot;
                + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-b&quot;
              }
            + default-asia-southeast1-c  = {
                + id                    = &quot;projects/k8s-playground-public/zones/asia-southeast1-c/networkEndpointGroups/name-1&quot;
                + name                  = &quot;name-1&quot;
                + zone                  = &quot;https://www.googleapis.com/compute/v1/projects/k8s-playground-public/zones/asia-southeast1-c&quot;
              }
          },
      ]
  </code></pre>
  <p>and how i access this <code>id</code> of data.</p>