Need to create multile vms in azure through terraform

前端 未结 1 424
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 06:56

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

相关标签:
1条回答
  • 2021-01-16 07:11

    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.

    0 讨论(0)
提交回复
热议问题