I\'m facing issues during creation of multiple VMs in Azure with Terraform. Each time it is failing because it is picking the same network-interface-id. So how can I change
If you're trying to link two resources as you loop through them then you need to use "splats" to retrieve the list of resources created in a loop and select the right one. This is explained briefly in the interpolation syntax docs and the resources docs.
In your case you probably want something like:
variable "count" {default = 2}
resource "azurerm_network_interface" "terraform-CnetFace" {
count = "${var.count}"
...
}
resource "azurerm_virtual_machine" "terraform-test" {
count = "${var.count}"
...
network_interface_ids = ["${element(azurerm_network_interface.terraform-CnetFace.*.id, count.index)}"]
...
}
This exposes the outputs for each of the looped network interfaces created and then loops through them grabbing the id
from the output and passing it to the appropriate azurerm_virtual_machine
.