为变量指定类型的正确方法是什么?该变量是`List with map和map with any type of values。
我尝试过type = list(map(any))
,但收到错误element 0: all map elements must have the same type.
variable "ingress_rules" {
type = list(map(any))
}
我想知道我是否应该完全不为该类型指定任何内容?
下面是ingress_rules的样子:
module "prod_security_groups" {
source = "../modules/security_groups"
name = "Inbout traffic for WebServers"
ingress_rules = [
{description: "Port 3306", cidr_blocks: ["10.0.0.0/24", "10.0.4.0/24"], port: 3306, protocol: "tcp"},
{description: "Port 22", cidr_blocks: ["0.0.0.0/0"], port: 22, protocol: "tcp"},
{description: "port 80", cidr_blocks: ["0.0.0.0/0"], port: 80, protocol: "tcp"}
]
tags = {
Name = "SG WebServers"
}
}
类型实际上是一个可选的东西。
Map实际上只支持某个类型,它的所有元素都应该是字符串或int或其他类型。你有一个对象列表,所以你可以尝试使用:
type = list(
object({
description = string
cidr_blocks = list(string)
port = number
protocol = string
})
)
variable "ingress_rules" {
type = any
}