无法从 terraform 0.12 中的模块输出访问列表的所有元素

Unable to access all the elements of a list from module output in terraform 0.12

我无法使用模块输出将多个网卡连接到单个虚拟机。似乎元素函数一次只能通过一个元素。有什么方法可以让我们只调用模块输出列表中的特定索引。 Terraform v0.12.7

    # Virtual Machine module main.tf
    resource "azurerm_virtual_machine" "vm" {
      count                        = var.vm_instances_count
      name                         = "${var.vm_name}${format(var.count_format, var.count_offset + count.index + 1)}"
      location                     = var.location
      availability_set_id          = var.avset_id
      primary_network_interface_id = var.multi_nic == "true" ? var.primary_nic_id : null
      resource_group_name          = var.resource_group_name
      network_interface_ids        = [element(var.nic, count.index)]
      vm_size                      = var.vm_size
      ......
      }

    # environments/dev/main.tf (calling nic module)
    module "fw_nic" {
      source               = "../../nic"
      vm_name              = var.fw_vm_name
      location             = var.location
      resource_group_name  = module.resource_group.name
      vm_instances_count   = var.fw_vm_nic_count
      vnet_subnet_id       = module.fw_subnet.subnet_id[0]
      nsg_id               = module.fw_nsg.nsg_id[0]
      lb_enable            = "no"
      enable_ip_forwarding = "true"
      ......
    }

# environments/dev/main.tf (calling vm module)
module "fw_vm" {
  source              = "../../virtual_machines"
  vm_name             = var.fw_vm_name
  location            = var.location
  resource_group_name = module.resource_group.name
  vm_instances_count  = var.fw_vm_instances_count
  vm_size             = var.fw_vm_size
  admin_username      = var.fw_vm_admin_username
  admin_password      = var.fw_vm_admin_password
  nic                 = [module.fw_nic.nic_id]
  primary_nic_id      = module.fw_nic.nic_id[0]
  .....   
}

您应该可以像下面这样直接使用逗号分隔 var.nic[0], var.nic[2]

    # Virtual Machine module main.tf
    resource "azurerm_virtual_machine" "vm" {
      count                        = var.vm_instances_count
      name                         = "${var.vm_name}${format(var.count_format, var.count_offset + count.index + 1)}"
      location                     = var.location
      availability_set_id          = var.avset_id
      primary_network_interface_id = var.multi_nic == "true" ? var.primary_nic_id : null
      resource_group_name          = var.resource_group_name
      network_interface_ids        = [var.nic[0], var.nic[2]]
      vm_size                      = var.vm_size
      ......
      }

希望对您有所帮助!