使用不同的 NIC 在 Azure 中创建多个 VM



我想在不同的位置创建两个具有不同网卡的虚拟机。这是我的代码,但我有一个错误,我不知道为什么,因为在编译代码时建议使用此解决方案:

variable "locations" {
type = map(string)
default = {
vm1 = "North Europe"
vm2 = "West Europe"
}
}
resource "azurerm_network_interface" "main" {
for_each            = var.locations
name                = "${each.key}-nic"
location            = "${each.value}"
resource_group_name = var.azurerm_resource_group_name
ip_configuration {
name                          = "testconfiguration1"
subnet_id                     = azurerm_subnet.internal.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id          = azurerm_public_ip.example.id
}
}

resource "azurerm_virtual_machine" "main" {
for_each              = var.locations
name                  = "${each.key}t-vm"
location              = "${each.value}"
resource_group_name   = var.azurerm_resource_group_name
network_interface_ids = [azurerm_network_interface.main[each.key]]
vm_size               = "Standard_D2s_v3"
...
}

错误:

Error: Incorrect attribute value type
on environment.tf line 68, in resource "azurerm_virtual_machine" "main":
68:   network_interface_ids = [azurerm_network_interface.main[each.key]]
|----------------
| azurerm_network_interface.main is object with 2 attributes
| each.key is "vm2"
Inappropriate value for attribute "network_interface_ids": element 0: string
required.

尝试

network_interface_ids = [azurerm_network_interface.main[each.key].id]

最新更新