amazon-web-services - 将地图转换为 terraform aws_autoscaling_group 的列表
问题描述
我有以下子网 ID 映射作为要在 Terraformaws_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}"
所以非常想要一种能够使用地图并能够根据选择的区域传入列表的方法
谢谢
解决方案
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)}"]
推荐阅读
- microcontroller - wifi模块中应用处理器的目的是什么?
- python-3.x - For 循环 - 缩进问题。需要重新安排
- bash - 如何将 bash 函数指定为 scp -S 作为参数
- html - 页脚版权和设计者居中导航栏不是
- c# - 使用 AC/SC 读卡器从 Mifare Ultralight 卡获取原创签名
- javascript - Redux Reducer 更新值但未反映在 props 中
- php - 将 API 代码转换为 PHP CURL 时出现问题
- java - 如何使用java交换非常大文件中的行和列
- c# - 项目中的额外文件 (NPGSQL)
- stanford-nlp - 斯坦福 NLP 核心未在标记化中生成“之前”和“之后”节点