【发布时间】:2017-07-23 11:48:30
【问题描述】:
我正在尝试设置一个通用但可自定义的模板。
所以使用模块,我想遍历包含列表的地图,例如:
module "instance"
{
...
ip_by_subnets = {
subnet1 = [ip1,ip2]
subnet2 = [ip3]
subnet3 = []
subnet4 = [ip4,ip5,ip6,...]
}
...
}
在哪里
subnet# = a subnet cidr block
ip# = private IP address
对于每个子网,我需要运行并为每个私有 ip 创建一个实例。
伪代码基本上会这样做:
foreach subnet# in ip_by_subnets
foreach ip# in list
create an instance resource
但我不知道要放入资源模板的代码。 做了一些不好的尝试,例如
subnet_id = "${element(var.ip_by_subnets[count.index])}"
但这不会正常工作。
我还考虑过在模块中使用count,但是我不得不将elb 移到它自己的模块中。我可以,但我想先试试这个方法
有人知道怎么做吗? 对其他方法的任何建议(例如,不同的数据结构表示赞赏)
【问题讨论】:
-
您是否完全设置在该数据结构上,还是可以不同?
-
@ydaetskcoR 它可以不同,我只是喜欢它的样子。任何建议表示赞赏。
标签: amazon-web-services terraform