title: Terraform v12 Dynamic Nested Block with multiple content fields?
body: <p>I'm running into an issue with my module for an Azure App Gateway. I have converted everything to dynamic blocks, and when I call upon my module with the input for 1 app, it works splendidly.</p>
  <h2>1 App:</h2>
  <pre><code>module &quot;my_appgw&quot; {
    source = &quot;../../../modules/module-application-gateway&quot;
    location                    = var.location
    resource_group_name         = var.rsg
    subnet_id                   = &quot;${data.azurerm_virtual_network.vnet_dmz.id}/subnets/waf&quot;
  
    app = [
      {
        name                        = &quot;app1-example.com&quot;
        pick_host_name_from_backend = true,
      },
    ]
  }
  </code></pre>
  <p>However, when i add the 2nd app to my call, this is when I see issues.</p>
  <h2>2 apps</h2>
  <pre><code>module &quot;my_appgw&quot; {
    source = &quot;../../../modules/module-application-gateway&quot;
    location                    = var.location
    resource_group_name         = var.rsg
    subnet_id                   = &quot;${data.azurerm_virtual_network.vnet_dmz.id}/subnets/waf&quot;
  
    app = [
      {
        name                        = &quot;app1-example.com&quot;
        pick_host_name_from_backend = true,
      },
      {
        name                        = &quot;app2-example.com&quot;
      }
    ]
  }
  </code></pre>
  <p>When adding a new app, it has both the 80 redirect, and the 443 rule. However because of the indexing, terraform wants to overwrite my first app rule so that both 80 redirect rules are first and second in the list, followed by the 443 rules third and fourth in the list. Can we do multiple content blocks in one dynamic block? As you can see the first app is changing when I'm adding in the second app to the module, making the keys not match up (i.e app1 id mismatches to app2 key, etc). The same thing occurs for my http_listener</p>
  <h2>Output Changes</h2>
  <pre><code>request_routing_rule {
  
  backend_address_pool_id = &quot;&lt;output omitted&gt;/backendAddressPools/app1-example.com&quot;
  
  backend_address_pool_name = &quot;app1-example.com&quot;
  
  backend_http_settings_id = &quot;&lt;output omitted&gt;/backendHttpSettingsCollection/app1-example.com-https-settings&quot;
  
  backend_http_settings_name = &quot;app1-example.com-https-settings&quot;
  
  http_listener_id = &quot;&lt;output omitted&gt;/httpListeners/app1-example.com-443-https-list&quot;
  
  http_listener_name = &quot;app1-example.com-443-https-list&quot;
  
  id = &quot;&lt;output omitted&gt;/requestRoutingRules/app1-example.com-443&quot;
  
  name = &quot;app1-example.com-443&quot;
  
  rule_type = &quot;Basic&quot;
  
  }
  
  ~ request_routing_rule {
  
  + backend_address_pool_name = &quot;app2-example.com&quot;
  
  + backend_http_settings_name = &quot;app2-example.com-https-settings&quot;
  
  http_listener_id = &quot;&lt;output omitted&gt;/httpListeners/app1-example.com-http-list&quot;
  
  ~ http_listener_name = &quot;app1-example.com-http-list&quot; -&gt; &quot;app2-example.com-443-https-list&quot;
  
  id = &quot;&lt;output omitted&gt;/requestRoutingRules/app1-example.com-http-redirect&quot;
  
  ~ name = &quot;app1-example.com-http-redirect&quot; -&gt; &quot;app2-example.com-443&quot;
  
  redirect_configuration_id = &quot;&lt;output omitted&gt;/redirectConfigurations/app1-example.com-redirect&quot;
  
  - redirect_configuration_name = &quot;app1-example.com-redirect&quot; -&gt; null
  
  rule_type = &quot;Basic&quot;
  
  }
  
  + request_routing_rule {
  
  + http_listener_name = &quot;app1-example.com-http-list&quot;
  
  + name = &quot;app1-example.com-http-redirect&quot;
  
  + redirect_configuration_name = &quot;app1-example.com-redirect&quot;
  
  + rule_type = &quot;Basic&quot;
  
  }
  
  + request_routing_rule {
  
  + http_listener_name = &quot;app2-example.com-http-list&quot;
  
  + name = &quot;app2-example.com-http-redirect&quot;
  
  + redirect_configuration_name = &quot;app2-example.com-redirect&quot;
  
  + rule_type = &quot;Basic&quot;
  
  }
  </code></pre>
  <h2>Proposed config, doesn't work</h2>
  <h3>Multiple content blocks per dynamic block</h3>
  <pre><code>    for_each = [for i in var.app : {
        name = i.name
      }]
      content {
        name                           = &quot;${http_listener.value.name}-${local.http_listener_name}&quot;
        frontend_ip_configuration_name = local.frontend_ip_configuration_name
        frontend_port_name             = 80
        protocol                       = &quot;Http&quot;
      }
      content {
        name                           = &quot;${http_listener.value.name}-${http_listener.value.port}-${local.https_listener_name}&quot;
        frontend_ip_configuration_name = local.frontend_ip_configuration_name
        frontend_port_name             = http_listener.value.port
        ssl_certificate_name           = data.azurerm_key_vault_secret.cert_fe.name
        protocol                       = &quot;Https&quot;
      }
    }
  </code></pre>
  <h3>Or Nested dynamic blocks within a dynamic block, also doesn't work</h3>
  <pre><code>dynamic &quot;http_listener&quot; {
      for_each = [for i in var.app : {
        name = i.name
      }]
      content {
        name                           = &quot;${http_listener.value.name}-${local.http_listener_name}&quot;
        frontend_ip_configuration_name = local.frontend_ip_configuration_name
        frontend_port_name             = 80
        protocol                       = &quot;Http&quot;
  
        dynamic &quot;http_listener&quot; {
          for_each = [for i in var.app : {
            name = i.name
            port = lookup(i, &quot;frontend_port&quot;, 443) 
          }]
          content {
            name                           = &quot;${http_listener.value.name}-${http_listener.value.port}-${local.https_listener_name}&quot;
            frontend_ip_configuration_name = local.frontend_ip_configuration_name
            frontend_port_name             = http_listener.value.port
            ssl_certificate_name           = data.azurerm_key_vault_secret.cert_fe.name
            protocol                       = &quot;Https&quot;
          }
        }
      }
  </code></pre>
  <p>Does anyone have any idea how to fix this? Makes the app gateway module unusable if existing apps will change and have to be tainted and recreated everytime a new app is added.</p>