title: terraform reporting error "cannot use element function with an empty list"
body: <p>My NIC creation code is as below:</p>
  
  <pre><code>resource "azurerm_network_interface" "tf-ni-test" {
   count                     = "${var.count_sss_vm}"
   name                      = "${var.sss_base_hostname}${format("%02d",count.index+1)}-nic01"
   #location                 = "${data.azurerm_resource_group.tf-rg-test-external.location}"
   location                  = "${var.location}"  
   resource_group_name       = "${data.azurerm_resource_group.tf-rg-test-external.name}"
  
   ip_configuration {
      name                          = "${var.sss_base_hostname}${format("%02d",count.index+1)}-iip01"
      subnet_id                     = "${data.azurerm_subnet.tf-sn-test.id}"
      private_ip_address_allocation = "${var.env=="msdn"?"dynamic":"static"}"
      #private_ip_address            = "10.112.2.${count.index+10}"
      public_ip_address_id          = "${element(azurerm_public_ip.tf-pip-test.*.id,count.index+1)}"
   }
  }
  </code></pre>
  
  <p>VM creation code is as below:</p>
  
  <pre><code>resource "azurerm_virtual_machine" "tf-vm-test" {
    count                 = "${var.count_sss_vm}"
    name                  = "${var.sss_base_hostname}${format("%02d",count.index+1)}"
    location              = "${var.location}"  
    #location              = "${data.azurerm_resource_group.tf-rg-test-external.location}"
    resource_group_name   = "${data.azurerm_resource_group.tf-rg-test-external.name}"
    network_interface_ids = ["${element(azurerm_network_interface.tf-ni-test.*.id, count.index)}"]
    vm_size               = "${var.sss_vm_size}"
  .
  .
  .
  }
  </code></pre>
  
  <p>I'm running terraform plan with below command:</p>
  
  <pre><code>terraform plan -var "application_nsg=test-sss" -var "count_sss_vm=2" -var "env=msdn" -var "username=devopsadmin" -var "password=Angular1@#$" -var "sss_base_hostname=testsss" -var "sss_vm_size=Standard_B2s" -var "storage_account_suffix=sta" -var "win_image_offer=Windows" -var "win_image_publisher=microsoftvisualstudio" -var "win_sku=Windows-10-N-x64" -var "location=australiaeast"
  </code></pre>
  
  <p>Curious to know why it is reporting error and how to resolve it. The same code has well before. Is this because of TF v0.12?</p>
  
  <p>I found similar issue on github and in fact using the same method given by Hashicorp:
  <a href="https://github.com/terraform-providers/terraform-provider-azurerm/issues/3979" rel="nofollow noreferrer">https://github.com/terraform-providers/terraform-provider-azurerm/issues/3979</a></p>
  
  <p>I'm getting error like below:</p>
  
  <pre><code>Error: Error in function call
  
    on frednxt_tpi_standalone.tf line 123, in resource "azurerm_virtual_machine" "tf-vm-test":
   123:   network_interface_ids = ["${element(azurerm_network_interface.tf-ni-test.*.id, count.index)}"]
      |----------------
      | azurerm_network_interface.tf-ni-test is empty tuple
      | count.index is 0
  
  Call to function "element" failed: cannot use element function with an empty
  list.
  
  
  Error: Error in function call
  
    on frednxt_tpi_standalone.tf line 123, in resource "azurerm_virtual_machine" "tf-vm-test":
   123:   network_interface_ids = ["${element(azurerm_network_interface.tf-ni-test.*.id, count.index)}"]
      |----------------
      | azurerm_network_interface.tf-ni-test is empty tuple
      | count.index is 1
  
  Call to function "element" failed: cannot use element function with an empty
  list.
  </code></pre>