title: Using Terraform random_id to create multiple resources not working as expected
body: <p>I'm trying to combine the usage of the random_id attribute with the count meta attribute to create multiple Azure storage accounts with unique names. </p>
  
  <p><strong>Configuration code:</strong></p>
  
  <pre><code># Create storage accounts
  
  resource "random_id" "storage_account_name_unique" {
    byte_length = 8
  }
  
  resource "azurerm_storage_account" "storage" {
    count                    = "${var.storage_account_count}"
    name                     = "tfsta${lower(random_id.storage_account_name_unique.hex)}"
    resource_group_name      = "${azurerm_resource_group.rg.name}"
    location                 = "${azurerm_resource_group.rg.location}"
    account_kind             = "StorageV2"
    account_tier             = "Standard"
    access_tier              = "Hot"
    account_replication_type = "${var.account_replication_type}"
  
    network_rules {
      ip_rules                   = ["127.0.0.1"]
      virtual_network_subnet_ids = ["${azurerm_subnet.subnet.id}"] 
    }
  
    tags = "${var.tags}"
    }
  </code></pre>
  
  <p><strong>Problems with this code:</strong></p>
  
  <ol>
  <li>Terraform is only generating a single random_id and uses it for all of the storage account instances created during terraform apply operation. </li>
  <li>Terraform is "fooled" into thinking it has created multiple storage accounts however only one storage account gets created</li>
  </ol>
  
  <p><strong>Selected Terraform Apply output:</strong> </p>
  
  <p>This output shows that Terraform thinks it is creating three separate storage accounts with the same random_id. The plan is successfully applied but there is only one storage account created in Azure.</p>
  
  <pre><code>random_id.storage_account_name_unique: Creating...
    b64:         "" =&gt; "&lt;computed&gt;"
    b64_std:     "" =&gt; "&lt;computed&gt;"
    b64_url:     "" =&gt; "&lt;computed&gt;"
    byte_length: "" =&gt; "8"
    dec:         "" =&gt; "&lt;computed&gt;"
    hex:         "" =&gt; "&lt;computed&gt;"
  random_id.storage_account_name_unique: Creation complete after 0s (ID: kYl9WvpTSso)
  
  azurerm_storage_account.storage[2]: Creating...
    access_tier:                                           "" =&gt; "Hot"
    account_encryption_source:                             "" =&gt; "Microsoft.Storage"
    account_kind:                                          "" =&gt; "StorageV2"
    account_replication_type:                              "" =&gt; "LRS"
    account_tier:                                          "" =&gt; "Standard"
    enable_blob_encryption:                                "" =&gt; "true"
    enable_file_encryption:                                "" =&gt; "true"
    identity.#:                                            "" =&gt; "&lt;computed&gt;"
    location:                                              "" =&gt; "westus2"
    name:                                                  "" =&gt; "tfsta91897d5afa534aca"
    network_rules.#:                                       "" =&gt; "1"
    network_rules.0.bypass.#:                              "" =&gt; "&lt;computed&gt;"
    network_rules.0.ip_rules.#:                            "" =&gt; "1"
    network_rules.0.ip_rules.3619153832:                   "" =&gt; "127.0.0.1"
    network_rules.0.virtual_network_subnet_ids.#:          "" =&gt; "1"
    network_rules.0.virtual_network_subnet_ids.3223410521: "" =&gt; "/subscriptions/f6d69ee2-34d5-4ca8-a143-7a2fc1aeca55/resourceGroups/hdi-dev-rg/providers/Microsoft.Network/virtualNetworks/hdi-dev-vnet/subnets/hdinsight"
    primary_access_key:                                    "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_connection_string:                        "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_connection_string:                             "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_file_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_location:                                      "" =&gt; "&lt;computed&gt;"
    primary_queue_endpoint:                                "" =&gt; "&lt;computed&gt;"
    primary_table_endpoint:                                "" =&gt; "&lt;computed&gt;"
    resource_group_name:                                   "" =&gt; "hdi-dev-rg"
    secondary_access_key:                                  "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_connection_string:                      "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_endpoint:                               "" =&gt; "&lt;computed&gt;"
    secondary_connection_string:                           "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_location:                                    "" =&gt; "&lt;computed&gt;"
    secondary_queue_endpoint:                              "" =&gt; "&lt;computed&gt;"
    secondary_table_endpoint:                              "" =&gt; "&lt;computed&gt;"
    tags.%:                                                "" =&gt; "3"
    tags.costcenter:                                       "" =&gt; "Unknown"
    tags.environment:                                      "" =&gt; "Dev"
    tags.project:                                          "" =&gt; "Unknown"
  azurerm_storage_account.storage[1]: Creating...
    access_tier:                                           "" =&gt; "Hot"
    account_encryption_source:                             "" =&gt; "Microsoft.Storage"
    account_kind:                                          "" =&gt; "StorageV2"
    account_replication_type:                              "" =&gt; "LRS"
    account_tier:                                          "" =&gt; "Standard"
    enable_blob_encryption:                                "" =&gt; "true"
    enable_file_encryption:                                "" =&gt; "true"
    identity.#:                                            "" =&gt; "&lt;computed&gt;"
    location:                                              "" =&gt; "westus2"
    name:                                                  "" =&gt; "tfsta91897d5afa534aca"
    network_rules.#:                                       "" =&gt; "1"
    network_rules.0.bypass.#:                              "" =&gt; "&lt;computed&gt;"
    network_rules.0.ip_rules.#:                            "" =&gt; "1"
    network_rules.0.ip_rules.3619153832:                   "" =&gt; "127.0.0.1"
    network_rules.0.virtual_network_subnet_ids.#:          "" =&gt; "1"
    network_rules.0.virtual_network_subnet_ids.3223410521: "" =&gt; "/subscriptions/f6d69ee2-34d5-4ca8-a143-7a2fc1aeca55/resourceGroups/hdi-dev-rg/providers/Microsoft.Network/virtualNetworks/hdi-dev-vnet/subnets/hdinsight"
    primary_access_key:                                    "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_connection_string:                        "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_connection_string:                             "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_file_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_location:                                      "" =&gt; "&lt;computed&gt;"
    primary_queue_endpoint:                                "" =&gt; "&lt;computed&gt;"
    primary_table_endpoint:                                "" =&gt; "&lt;computed&gt;"
    resource_group_name:                                   "" =&gt; "hdi-dev-rg"
    secondary_access_key:                                  "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_connection_string:                      "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_endpoint:                               "" =&gt; "&lt;computed&gt;"
    secondary_connection_string:                           "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_location:                                    "" =&gt; "&lt;computed&gt;"
    secondary_queue_endpoint:                              "" =&gt; "&lt;computed&gt;"
    secondary_table_endpoint:                              "" =&gt; "&lt;computed&gt;"
    tags.%:                                                "" =&gt; "3"
    tags.costcenter:                                       "" =&gt; "Unknown"
    tags.environment:                                      "" =&gt; "Dev"
    tags.project:                                          "" =&gt; "Unknown"
  azurerm_storage_account.storage[0]: Creating...
    access_tier:                                           "" =&gt; "Hot"
    account_encryption_source:                             "" =&gt; "Microsoft.Storage"
    account_kind:                                          "" =&gt; "StorageV2"
    account_replication_type:                              "" =&gt; "LRS"
    account_tier:                                          "" =&gt; "Standard"
    enable_blob_encryption:                                "" =&gt; "true"
    enable_file_encryption:                                "" =&gt; "true"
    identity.#:                                            "" =&gt; "&lt;computed&gt;"
    location:                                              "" =&gt; "westus2"
    name:                                                  "" =&gt; "tfsta91897d5afa534aca"
    network_rules.#:                                       "" =&gt; "1"
    network_rules.0.bypass.#:                              "" =&gt; "&lt;computed&gt;"
    network_rules.0.ip_rules.#:                            "" =&gt; "1"
    network_rules.0.ip_rules.3619153832:                   "" =&gt; "127.0.0.1"
    network_rules.0.virtual_network_subnet_ids.#:          "" =&gt; "1"
    network_rules.0.virtual_network_subnet_ids.3223410521: "" =&gt; "/subscriptions/f6d69ee2-34d5-4ca8-a143-7a2fc1aeca55/resourceGroups/hdi-dev-rg/providers/Microsoft.Network/virtualNetworks/hdi-dev-vnet/subnets/hdinsight"
    primary_access_key:                                    "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_connection_string:                        "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_blob_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_connection_string:                             "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    primary_file_endpoint:                                 "" =&gt; "&lt;computed&gt;"
    primary_location:                                      "" =&gt; "&lt;computed&gt;"
    primary_queue_endpoint:                                "" =&gt; "&lt;computed&gt;"
    primary_table_endpoint:                                "" =&gt; "&lt;computed&gt;"
    resource_group_name:                                   "" =&gt; "hdi-dev-rg"
    secondary_access_key:                                  "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_connection_string:                      "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_blob_endpoint:                               "" =&gt; "&lt;computed&gt;"
    secondary_connection_string:                           "&lt;sensitive&gt;" =&gt; "&lt;sensitive&gt;"
    secondary_location:                                    "" =&gt; "&lt;computed&gt;"
    secondary_queue_endpoint:                              "" =&gt; "&lt;computed&gt;"
    secondary_table_endpoint:                              "" =&gt; "&lt;computed&gt;"
    tags.%:                                                "" =&gt; "3"
    tags.costcenter:                                       "" =&gt; "Unknown"
    tags.environment:                                      "" =&gt; "Dev"
    tags.project:                                          "" =&gt; "Unknown"
  azurerm_storage_account.storage[0]: Creation complete after 21s (ID: /subscriptions/f6d69ee2-34d5-4ca8-a143-.../storageAccounts/tfsta91897d5afa534aca)
  azurerm_storage_account.storage[2]: Creation complete after 22s (ID: /subscriptions/f6d69ee2-34d5-4ca8-a143-.../storageAccounts/tfsta91897d5afa534aca)
  azurerm_storage_account.storage[1]: Creation complete after 23s (ID: /subscriptions/f6d69ee2-34d5-4ca8-a143-.../storageAccounts/tfsta91897d5afa534aca)
  </code></pre>