我正在尝试创建一个文件,其中包含使用以下count
属性生成的多个服务器主机的 ID :
resource "aws_instance" "workers" {
count = "${var.worker_count}"
...
}
resource "local_file" "stop_instances" {
filename = "${path.module}/generated/stop_instances.py"
content =<<EOF
import boto3
# Boto Connection
ec2 = boto3.resource('ec2', '${var.region}')
def lambda_handler(event, context):
# Retrieve instance IDs
instance_ids = ["${aws_instance.controller.id}", "${aws_instance.gateway.id}", "${aws_instance.workers.*.id}"]
# stopping instances
stopping_instances = ec2.instances.filter(InstanceIds=instance_ids).stop()
EOF
}
但是,我收到以下错误:
447: instance_ids = ["${aws_instance.controller.id}",
"${aws_instance.gateway.id}", "${aws_instance.workers.*.id}"]
449:
450:
451:
|----------------
| aws_instance.workers is tuple with 3 elements
Cannot include the given value in a string template: string required.
有没有办法将元组展平为字符串?
我试过tostring()方法,但它只接受原始类型。
加入是我的解决方案:
instance_ids = ["${aws_instance.controller.id}","${aws_instance.gateway.id}","${join("\",\"", aws_instance.workers.*.id)}"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句