gpt4 book ai didi

azure - 如何在 Azure 中使用 Terraform 创建多个安全规则?

转载 作者:行者123 更新时间:2023-12-02 07:35:18 25 4
gpt4 key购买 nike

我正在尝试创建一个包含多个安全规则的网络安全组。这个想法是创建一个列表变量(端口范围)并在 .tf 文件中插入列表项。下面的脚本抛出一个错误“优先级”。

"Error: azurerm_network_security_group.k8hway: security_rule.0: invalid or unknown key: count"

下面是 Terraform 代码:​​

resource "azurerm_network_security_group" "NSG" {
name = "NSG-Demo"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"

security_rule {
count = "${length(var.inbound_port_ranges)}"
name = "sg-rule-${count.index}"
direction = "Inbound"
access = "Allow"
priority = "(100 * (${count.index} + 1))"
source_address_prefix = "*"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "${element(var.inbound_port_ranges, count.index)}"
protocol = "TCP"
}
}

最佳答案

我认为属性不支持计数,但资源支持。使用网络安全组规则:

resource "azurerm_network_security_rule" "test" {
count = "${length(var.inbound_port_ranges)}"
name = "sg-rule-${count.index}"
direction = "Inbound"
access = "Allow"
priority = "(100 * (${count.index} + 1))"
source_address_prefix = "*"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "${element(var.inbound_port_ranges, count.index)}"
protocol = "TCP"
}

阅读:

https://www.terraform.io/docs/providers/azurerm/r/network_security_rule

关于azure - 如何在 Azure 中使用 Terraform 创建多个安全规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54744311/

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