0

我正在尝试从变量文件中的列表创建多个虚拟机。我有一个包含两个虚拟机名称的列表。我可以创建它们,但是当我尝试使用 count 命令时,它无法正确循环以将 nics 分配给 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"

在此处输入图像描述

4

0 回答 0