无法在创建虚拟机时使用副本-Terraform

时间:2019-11-13 13:24:24

标签: terraform terraform-provider-azure infrastructure-as-code

我正在尝试从变量文件中的列表创建多个虚拟机。我有一个包含两个虚拟机名称的列表。我可以创建它们,但是当我尝试使用count命令时,它无法正确循环以将nic分配给vm。请看下面。我收到的错误是“对函数“元素”的调用失败:无法将元素函数与空列表一起使用。

    resource "azurerm_network_interface" "VM01" {
  count               = "${length(var.Numberofdcs)}"
  name                = "${element(var.Numberofdcs, count.index)}-nic"
  location            = "${var.Location}"
  resource_group_name = "${azurerm_resource_group.ProdInfraRG.name}"

  ip_configuration {
    name                          = "ipconfig"
    subnet_id                     = "${data.azurerm_subnet.ProdVNet.id}"
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_virtual_machine" "VMCreation" {
  count                 = "${length(var.Numberofdcs)}"
  name                  = "${element(var.Numberofdcs, count.index)}"
  location              = "${var.Location}"
  resource_group_name   = "${azurerm_resource_group.ProdInfraRG.name}"
  network_interface_ids = "${element(azurerm_network_interface.VM01.*.id, count.index)}"
  vm_size               = "Standard_DS1_v2"

enter image description here

0 个答案:

没有答案