Create dynamic resources using 'for_each' or 'for' I want to create multiple resources using this:
resource &quot;group&quot; &quot;list&quot; {
 g_name      = group_name
 p_name      = project_name
}

The input local variable is nested:
&gt; local.input
{
  &quot;group&quot; = [
    {
      &quot;name&quot; = &quot;group1&quot;
      &quot;projects&quot; = [
        &quot;project1&quot;,
        &quot;project3&quot;,
      ]
    },
    {
      &quot;name&quot; = &quot;group2&quot;
      &quot;projects&quot; = [
        &quot;project18&quot;,
        &quot;project31&quot;,
      ]
    },
  ]

I am able to transform it into a better form:
&gt; flatten([for grp_key, group in local.input.group: [for project in group.projects: { group_name=group.name, project_name=project} ]])
[
  {
    &quot;group_name&quot; = &quot;group1&quot;
    &quot;project_name&quot; = &quot;project1&quot;
  },
  {
    &quot;group_name&quot; = &quot;group1&quot;
    &quot;project_name&quot; = &quot;project3&quot;
  },
  {
    &quot;group_name&quot; = &quot;group2&quot;
    &quot;project_name&quot; = &quot;project18&quot;
  },
  {
    &quot;group_name&quot; = &quot;group2&quot;
    &quot;project_name&quot; = &quot;project31&quot;
  },
]

I can not use for_each because it is not map neither set.
How could I create multiple resources using the for like:
resource &quot;group&quot; &quot;list&quot; {
  for item in ... : 
    g_name=item.group_name
    p_name=item.project_name
}
you need to use count, and with it you should be able to access item by index: https://www.terraform.io/docs/configuration/resources.html#the-count-object