0
我尝试使用Terraform在Azure上创建2个虚拟机。通过索引访问模块的输出
我创建2个网卡一样
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时出错:错误 读取config for azurerm_virtual_machine [helloterraformvm]: azurerm_network_interface.helloterraformnic:资源变量必须 是三个部分:TYPE.NAME.ATTR在:
$ {元素(azurerm_network_interface.helloterraformnic,count.index)}
如何使用创建的上述使用索引的NIC?
感谢。这解决了我的问题。 – user1191140