Azure devops 地形表达
我正在开发这个azure_rm nsg(网络安全组)terraform模块,并试图使其成为变量驱动的通用模块。一切正常,但有一个标志出错 Main.tf文件Azure devops 地形表达,azure-devops,terraform,terraform-provider-azure,terraform-template-file,Azure Devops,Terraform,Terraform Provider Azure,Terraform Template File,我正在开发这个azure_rm nsg(网络安全组)terraform模块,并试图使其成为变量驱动的通用模块。一切正常,但有一个标志出错 Main.tf文件 `resource "azurerm_network_security_rule" "Inbound" { count = length(var.inbound_port_ranges) name = &qu
`resource "azurerm_network_security_rule" "Inbound" {
count = length(var.inbound_port_ranges)
name = "sg-rule-${count.index}"
direction = "Inbound"
access = "Allow"
priority = element(var.priority, count.index)
source_address_prefix = "*"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = element(var.inbound_port_ranges, count.index)
protocol = "TCP"
resource_group_name = azurerm_network_security_group.this.resource_group_name
network_security_group_name = azurerm_network_security_group.this.name
}
`
Variables.tf文件:
`variable "resource_group_name" {
default = "test"
}
variable "priority" {
default = ["100", "101"]
}
variable "inbound_port_ranges" {
default = ["8000", "8001"]
}
variable "outbound_port_ranges" {
default = ["9000", "9001"]
}
`
我能够将列表读入“destination\u port\u range”变量,但无法读入priority变量,它不断出错,出现以下错误,我不知道为什么
`Error: Incorrect attribute value type
on main.tf line 20, in resource "azurerm_network_security_rule" "Inbound":
20: priority = "element(var.priority, ${count.index})"
|----------------
| count.index is 1
Inappropriate value for attribute "priority": a number is required.
`
如果有人能为我指出解决问题的正确方向,我将非常感激。我只想从带有索引的列表中读取值,这样我就可以使用相同的入站规则创建多个规则
提前感谢。您的
优先级是字符串列表。此外,它将是字面上的字符串“元素(var.priority,)”
,而不是实际的数字
它应该是一个数字列表:
variable "priority" {
default = [100, 101]
}
然后:
priority = element(var.priority, count.index)
据我所知,你在目的地港口范围方面也会遇到同样的问题。你说得对@Marcin,结果很好。不幸的是,destination\u port\u range
没有抛出任何错误,但它确实存在相同的问题,我可以根据您的建议修复它。非常感谢。@Arun没问题。如果答案有帮助,我们将不胜感激。我们确实接受了您的答案。编辑并添加了正确的解决方案以供参考。。。