【发布时间】:2018-01-01 00:27:20
【问题描述】:
我正在尝试使用 Terraform 在 Azure 上创建 2 个 VM。
我创建了 2 个 NIC,例如
variable "internalips" {
description = "List of Internal IPs"
default = ["10.0.2.10", "10.0.2.11"]
type = "list"
}
resource "azurerm_network_interface" "helloterraformnic" {
count = 2
name = "nic-${count.index}"
location = "West US"
resource_group_name = "myrg"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.helloterraformsubnet.id}"
private_ip_address_allocation = "static"
private_ip_address = "${element(private_ip_address, count.index)}"
}
}
现在我想在模块 azurerm_virtual_machine 中使用它们
resource "azurerm_virtual_machine" "helloterraformvm" {
count = 2
name = "${element(elasticmachines, count.index)}"
location = "West US"
resource_group_name = "myrg"
network_interface_ids = "${element(azurerm_network_interface.helloterraformnic, count.index)}"
....
}
这给了我一个错误
无法加载根配置模块:加载 azure/rg.tf 时出错:错误 读取 azurerm_virtual_machine[helloterraformvm] 的配置: azurerm_network_interface.helloterraformnic:资源变量必须 分三部分:TYPE.NAME.ATTR in:
${element(azurerm_network_interface.helloterraformnic, count.index)}
如何使用上面创建的 NIC 使用索引?
【问题讨论】:
标签: terraform