我具有以下子网ID映射作为要在Terraform aws_autoscaling_group
资源中使用的变量:
subnet_ids = {
"us-east-1" = "subnet-123abc,subnet-456def,subnet-789ghi"
"us-west-2" = "subnet-1a2b3c,subnet-4c5d6e,subnet-7g8h9i"
}
,变量为
variable subnet_ids {
description = "subnet ids"
type = "map"
}
但是这不能正常工作,因为Terraform抱怨它需要一个列表但正在查看地图。
这是通过临时设置一个区域来实现的:
subnet_ids = ["subnet-123abc", "subnet-456def", "subnet-789ghi"]
,变量为:
variable subnet_ids {
description = "subnet ids"
type = "list"
}
并作为vpc_zone_identifier = "${var.subnet_ids}"
因此,非常需要一种方法来使用地图并根据所选择的区域传递列表
谢谢
答案 0 :(得分:1)
Try using the lookup
command and a variable to represent your region
to choose a value from your map
:
variable region {
description = "aws region"
default = "us-east-1"
}
...
vpc_zone_identifier = ["${lookup(var.subnet_ids, var.region)}"]
答案 1 :(得分:1)
对于在security groups
中要在Terraform中自动缩放组资源遇到问题的人,这就是将地图传递到列表的方式
这是有效的
security_groups = ["${split(",",lookup(var.security_groups, var.aws_region))}"]
答案 2 :(得分:0)
或者...
variable region {
description = "aws region"
default = "us-east-1"
}
...
vpc_zone_identifier = ["${var.subnet_ids["${var.region}"]}"]