问题
What would be the correct way to create type constraints for type map?
This doesn't seem valid.
variable "vpc_subnets" {
type = map(
key = {name = string, cidr_block = string, map_public_ip_on_launch = bool, availability_zone = string}
)
}
Here is what the map looks like..
vpc_subnets = {
"public_subnet_a" = {name = "public_test_a", cidr_block = "10.0.0.0/28", map_public_ip_on_launch = true, availability_zone = "ap-south-1a"},
"public_subnet_b" = {name = "public_test_b", cidr_block = "10.0.0.16/28", map_public_ip_on_launch = true, availability_zone = "ap-south-1b"},
"private_subnet_a" = {name = "private_test_a", cidr_block = "10.0.0.32/28", map_public_ip_on_launch = false, availability_zone = "ap-south-1a"},
"private_subnet_b" ={name = "private_test_b", cidr_block = "10.0.0.48/28", map_public_ip_on_launch = false, availability_zone = "ap-south-1b"}
}
回答1:
Your vpc_subnets
is map of objects, so you could use:
variable "vpc_subnets" {
type = map(
object({name = string, cidr_block = string, map_public_ip_on_launch = bool, availability_zone = string})
)
来源:https://stackoverflow.com/questions/64853110/terraform-create-type-constraints-for-type-map