title: Terraform looping in list of map
body: <p>I have a Terraform module that produces a list of map output:</p>
  <pre><code>object_ids = [
    {
      &quot;object_id&quot; = &quot;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&quot;
      &quot;upn&quot; = &quot;john@domain.com&quot;
      &quot;user&quot; = &quot;john&quot;
    },
    {
      &quot;object_id&quot; = &quot;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&quot;
      &quot;upn&quot; = &quot;martin@domain.com&quot;
      &quot;user&quot; = &quot;martin&quot;
    },
  ]
  </code></pre>
  <p>Using a for_each I can loop on one value to build this resource:</p>
  <pre><code>resource &quot;azurerm_role_assignment&quot; &quot;subread&quot; {
      for_each = toset(module.user.map_object_ids[*].object_id)
      scope                = data.azurerm_subscription.primary.id
      role_definition_name = &quot;Reader&quot;
      principal_id         = each.value
  }
  </code></pre>
  <p>However I don't know how to loop on more than one value.</p>
  <p>I tried the following for another resource requiring 2 different values from the output:</p>
  <pre><code>resource &quot;azurerm_role_assignment&quot; &quot;contribrg&quot; {
      scope                = [for map in module.user.map_object_ids[*]: &quot;${data.azurerm_subscription.primary.id}/resourceGroups/${lookup(map,&quot;user&quot;)}&quot;]
      role_definition_name = &quot;Contributor&quot;
      principal_id         = [for map in module.user.map_object_ids[*]: lookup(map,&quot;object_id&quot;)]
  }
  </code></pre>
  <p>Got the following errors :</p>
  <pre><code>Error: Incorrect attribute value type
  module.user.map_object_ids is tuple with 2 elements
  Inappropriate value for attribute &quot;scope&quot;: string required.
  Inappropriate value for attribute &quot;principal_id&quot;: string required.
  </code></pre>