gpt4 book ai didi

terraform - 从具有多个子网的虚拟网络中选择特定的子网 ID

转载 作者:行者123 更新时间:2023-12-05 03:59:33 25 4
gpt4 key购买 nike

我想在另一个资源 block 中引用 subnet 2 的 id,但子网没有索引值。即“${azurerm_virtual_network.test.subnet.2.id}”将不起作用。

resource "azurerm_virtual_network" "test" {
name = "virtualNetwork1"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
address_space = ["10.0.0.0/16"]
dns_servers = ["10.0.0.4", "10.0.0.5"]

subnet {
name = "subnet1"
address_prefix = "10.0.1.0/24"
}

subnet {
name = "subnet2"
address_prefix = "10.0.2.0/24"
}

subnet {
name = "subnet3"
address_prefix = "10.0.3.0/24"
security_group = "${azurerm_network_security_group.test.id}"
}
}

最佳答案

Expose ID of an embedded subnet defined in azurerm_virtual_network #1913 的帮助下解决了

...
subnet_id = "${azurerm_virtual_network.test.subnet.*.id[1]}"
...

关于terraform - 从具有多个子网的虚拟网络中选择特定的子网 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57118193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com