Terraform - Create type constraints for type Map

倾然丶 夕夏残阳落幕 提交于 2020-12-13 03:13:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!