gpt4 book ai didi

azure - TERRAFORM 如何在子网上设置 count.index 以检索 network_security_group_id

转载 作者:行者123 更新时间:2023-12-03 02:55:58 25 4
gpt4 key购买 nike

我觉得我的逻辑很糟糕!

我正在尝试将我的 Azure 网络组关联到我的子网

这是我的安全组配置

resource "azurerm_network_security_group" "azure_nsg" {
depends_on = ["azurerm_virtual_network.vnet"]
location = "${var.region}"
name = "${var.nsg_names[count.index]}" // I think my problem is here
resource_group_name = "${azurerm_resource_group.vnet.name}"
count = "${length(var.nsg_names)}"
}

我正在尝试从这个 count.index 导入

resource "azurerm_subnet" "subnet" {
depends_on = ["azurerm_network_security_group.private"]
name = "${var.subnet_names[count.index]}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.vnet.name}"
address_prefix = "${var.subnet_prefixes[count.index]}"
network_security_group_id = "${lookup(var.nsg_ids,var.subnet_names[count.index],"")}"
count = "${length(var.subnet_names)}"
}

但我无法使用 [count.index] 或 map 访问 network_security_group_id

 * azurerm_subnet.subnet.1: [ERROR] Unable to Parse Network Security Group ID 'databasensg': Cannot parse Azure ID: parse databasensg: invalid URI for request
* module.azure_vnet.azurerm_subnet.subnet[2]: 1 error(s) occurred:

* azurerm_subnet.subnet.2: [ERROR] Unable to Parse Network Security Group ID 'jumpboxnsg': Cannot parse Azure ID: parse jumpboxnsg: invalid URI for request
* module.azure_vnet.azurerm_network_security_group.azure_nsg[1]: 1 error(s) occurred:

对于地形改造专家来说,这将非常容易。

请帮忙,

最佳答案

Kiran,假设您的变量 nsg_names 是一个列表,您应该能够使用以下内容 -

resource "azurerm_network_security_group" "azure_nsg" {
depends_on = ["azurerm_virtual_network.vnet"]
location = "${var.region}"
name = "${element(var.nsg_names, count.index)}"
resource_group_name = "${azurerm_resource_group.vnet.name}"
count = "${length(var.nsg_names)}"
}

您应该在其他资源中执行的其他查找中使用相同的内容。

您可以阅读有关此插值函数的更多信息 here .

关于azure - TERRAFORM 如何在子网上设置 count.index 以检索 network_security_group_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52809020/

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