title: Terraform for_each - where is each.key defined?
body: <h3>Expected Behaviour</h3>
  <p>I'm trying to better understand the for_each loop</p>
  <p>Specifically where is the <strong>each.key</strong> value defined in the module call?<br />
  What would be an example of deploying 1 instance?  and then an example of multiple instances?<br />
  see  'Module call (parent module)' below</p>
  <h3>Actual Behavior</h3>
  <p>Not sure of expected outcome</p>
  <h3>Terraform (and AzureRM Provider) Version</h3>
  
  <h3>Affected Resource(s)</h3>
  
  <ul>
  <li><code>azurerm_v2.41.0</code></li>
  <li><code>terraform v0.13.0</code></li>
  </ul>
  <h3>Terraform Configuration Files</h3>
  
  <p><strong>Main.tf</strong></p>
  <pre><code>resource &quot;azurerm_resource_group_template_deployment&quot; &quot;sql_mi&quot; {
    for_each            = var.sql_mi_defaults
    
    name                = each.key # provide an example of how this is defined in module call?  # how would I deploy more than one instance?
    resource_group_name = var.resource_group_name
    deployment_mode     = var.deployment_mode
    template_content    = data.local_file.arm_template.content
    parameters_content  = &lt;&lt;PARAMETERS
       {
          &quot;managedInstanceName&quot;: {
              &quot;value&quot;: &quot;${each.value.managedInstanceName}&quot; 
          },
          &quot;location&quot;: {
              &quot;value&quot;: &quot;${var.location}&quot;
          },
          &quot;skuName&quot;: {
              &quot;value&quot;: &quot;${each.value.skuName}&quot;
          },
          &quot;storageSizeInGB&quot;: {
              &quot;value&quot;: &quot;${each.value.storageSizeInGB}&quot;
          },
          &quot;vCores&quot;: {
              &quot;value&quot;: &quot;${each.value.vCores}&quot;
          },
          &quot;licenseType&quot;: {
              &quot;value&quot;: &quot;${each.value.licenseType}&quot;
          },
          &quot;collation&quot;: {
              &quot;value&quot;: &quot;${each.value.collation}&quot;
          },
          &quot;timezoneId&quot;: {
              &quot;value&quot;: &quot;${each.value.timezoneId}&quot;
          },
          &quot;collation&quot;: {
              &quot;value&quot;: &quot;${each.value.collation}&quot;
          },
          &quot;proxyOverride&quot;: {
              &quot;value&quot;: &quot;${each.value.proxyOverride}&quot;
          },
          &quot;publicDataEndpointEnabled&quot;: {
              &quot;value&quot;: &quot;${each.value.publicDataEndpointEnabled}&quot;
          },
          &quot;administratorLogin&quot;: {
              &quot;value&quot;: &quot;azadmin-${random_string.mi_name.result}&quot;
          },
          &quot;administratorLoginPassword&quot;: {
              &quot;value&quot;: &quot;${random_password.admin.result}&quot;
          },
          &quot;managedInstanceTags&quot;: {
              &quot;value&quot;: &quot;${var.names.product_name}-${var.names.service_name}-${random_string.mi_name.result}&quot;
          },
          &quot;storageAccountType&quot;: {
              &quot;value&quot;: &quot;${each.value.storageAccountType}&quot;
          },
          &quot;virtualNetworkName&quot;: {
              &quot;value&quot;: &quot;${var.virtual_network_name}&quot;
          },
          &quot;virtualNetworkResourceGroupName&quot;: {
              &quot;value&quot;: &quot;${var.resource_group_name}&quot;
          },
      }
      PARAMETERS
  }
  </code></pre>
  <p><em><strong>Variables.tf</strong></em></p>
  <pre><code>variable sql_mi_defaults {
    type = any
    default = {
      managedInstanceName        = &quot;randomcomputername&quot;
      location                   = &quot;eastus2&quot;
      skuName                    = &quot;Standard_F2&quot;
      storageSizeInGB            = 256
      vCores                     = 8
      licenseType                = &quot;LicenseIncluded&quot;
      collation                  = &quot;SQL_Latin1_General_CP1_CI_AS&quot;
      timezoneId                 = &quot;UTC&quot;
      proxyOverride              = &quot;Proxy&quot;
      publicDataEndpointEnabled  = false
      minimalTlsVersion          = &quot;1.2&quot;
      administratorLogin         = &quot;azadmin&quot;
      administratorLoginPassword = &quot;&quot;
      managedInstanceTags        = &quot;&quot;
      storageAccountType         = &quot;GRS&quot;
  
    }
    description = &lt;&lt;EOT
  azure sql managed instance settings (only applied to virtual machine settings managed within this module)
      managedInstanceName             = (Required) The name of the Managed Instance.
      location                        = (Required) The location of the Managed Instance
      skuName                         = (Required) Managed instance SKU. If SKU is not set, skuEdition and hardwareFamily values have to be populated.&quot;
      storageSizeInGB                 = (Required) Determines how much Storage size in GB to associate with instance. Increments of 32 GB allowed only.
      vCores                          = (Required) The number of vCores.
      licenseType                     = (Optional) Determines license pricing model. Select 'LicenseIncluded' for a regular price inclusive of a new SQL license. Select 'Base Price' for a discounted AHB price for bringing your own SQL licenses.
      collation                       = (Optional) Specifies the priority of this Virtual Machine. Possible values are Regular and Spot. Defaults to Regular. Changing this forces a new resource to be created.
      timezoneId                      = (Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. At this time the only supported value is Deallocate. Changing this forces a new resource to be created. This can only be configured when priority is set to Spot.
      proxyOverride                   = (Optional) Determines connection type for private endpoint. Proxy connection type enables proxy connectivity to Managed Instance. Redirect mode enables direct connectivity to the instance resulting in improved latency and throughput.
      publicDataEndpointEnabled       = (Optional) Determines whether public data endpoint will be enabled, required for clients outside of the connected virtual networks. Public endpoint will always default to Proxy connection mode.
      administratorLogin              = (Required) The login of the Managed Instance admin.
      administratorLoginPassword      = (Required) The password of the Managed Instance admin.
      managedInstanceTags             = (Optional) Resource tags to associate with the instance.
      storageAccountType              = (Required) Option for configuring backup storage redundancy. Selecting 'GRS' will enable 'RA-GRS'.
      virtualNetworkName              = (Required) The virtual network name. Leave empty for the default value.
      virtualNetworkResourceGroupName = (Required) The resource group where the networking resources will be created or updated. Default is the same resource group as Managed Instance.
  EOT 
  }
  
  </code></pre>
  <h3>Module call (parent module)</h3>
  <pre><code># azurerm_sql_managed_instance see for more info https://docs.microsoft.com/en-us/azure/azure-sql/managed-instance/sql-managed-instance-paas-overview
  module &quot;sql_mi&quot; {
    source = &quot;github.com/[redacted]/azurerm-sql-managed-instance.git?ref=v2.3.1&quot;&quot;
  
    resource_group_name  = module.resource_group.name
    location             = module.resource_group.location
    deployment_mode      = &quot;Complete&quot;
    virtual_network_name = module.virtual_network.subnet_nsg_names[&quot;iaas-outbound&quot;]
  
    name = &quot;example-output-from-each.key&quot; # will the name of the instance be from each.key?
  }
  </code></pre>