title: Terraform 0.13 - Modules, for_each and providers
body: <p><strong>UPDATED</strong></p>
  <p>I am trying to provision multiple SQL databases in Azure using Terraform.</p>
  <p>My child module has the following code that provisions a SQL database:</p>
  <p><strong>providers.tf</strong></p>
  <pre><code>// default provider
  provider &quot;azurerm&quot; {
    alias = &quot;main&quot;
    features {}
  }
  
  // The provider that can access the storage account to store diagnostics
  provider &quot;azurerm&quot; {
    alias = &quot;storage_account&quot;
    features {}
  }
  </code></pre>
  <p><strong>sql_db.tf</strong></p>
  <pre><code>resource &quot;azurerm_mssql_database&quot; &quot;default&quot; {
    name      = var.name
    base_name = var.base_name
    ...
    tags      = var.tags
    
    provider = azurerm.main
  }
  </code></pre>
  <p><strong>data.tf</strong></p>
  <pre><code>data &quot;azurerm_storage_account&quot; &quot;storage&quot; {
    name = var.storage_account_name
    resource_group_name = var.storage_account_rg
    provider = azurerm.storage_account
  }
  </code></pre>
  <p>I am calling this module in my <strong>main.tf</strong> file as follows where I want to provision multiple SQL databases using a <code>for_each</code>:</p>
  <pre><code>module &quot;sql_db&quot; {
    for_each = var.sql_db
  
    source = &quot;...../sql_db.git&quot;
  
    base_name = each.value.base_name
    name      = each.value.name
  
    providers = {
      azurerm.main = azurerm.main
      azurerm.storage_account = azurerm.storage_account
    }
  }
  
  provider &quot;azurerm&quot; {
    features {}
    version  = &quot;=2.20.0&quot;
  }
  
  // default provider
  provider &quot;azurerm&quot; {
    alias = &quot;main&quot;
    features {}
  }
  
  provider &quot;azurerm&quot; {
    alias = &quot;storage_account&quot;
    features {}
  }
  </code></pre>
  <p>When I run plan, I get the following error:</p>
  <pre class="lang-bsh prettyprint-override"><code>Error: Module does not support for_each
  
    on main.tf line 35, in module &quot;sql_db&quot;:
    35:   for_each = var.sql_db
  
  Module &quot;sql_db&quot; cannot be used with for_each because it contains a nested
  provider configuration for &quot;azurerm.main&quot;, at
  .terraform\modules\sql_db\providers.tf:2,10-19.
  
  This module can be made compatible with for_each by changing it to receive all
  of its provider configurations from the calling module, by using the
  &quot;providers&quot; argument in the calling module block.
  
  
  Error: Module does not support for_each
  
    on main.tf line 35, in module &quot;sql_db&quot;:
    35:   for_each = var.sql_db
  
  Module &quot;sql_db&quot; cannot be used with for_each because it contains a nested
  provider configuration for &quot;azurerm.storage_account&quot;, at
  .terraform\modules\sql_db\providers.tf:8,10-19.
  
  This module can be made compatible with for_each by changing it to receive all
  of its provider configurations from the calling module, by using the
  &quot;providers&quot; argument in the calling module block.
  </code></pre>