【问题标题】:Create multiple VM's in Azure with different nic's在 Azure 中使用不同的 nic 创建多个 VM
【发布时间】:2020-05-21 12:10:29
【问题描述】:

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

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.

【问题讨论】:

  • 你能分享变量位置吗?如果你只是想在不同的区域和 NIC 创建多个 VM?
  • 我已经添加了这个变量。
  • 好吧,如果答案解决了您的问题,请接受它作为答案,以便它可以帮助正在搜索它的其他人。

标签: azure terraform terraform-provider-azure


【解决方案1】:

试试

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 2020-07-04
    • 2022-01-26
    相关资源
    最近更新 更多