如何将服务器 ID 元组展平为字符串?

克里斯·斯诺

我正在尝试创建一个文件,其中包含使用以下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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PHP 将多维数组展平为字符串

MySQL 将 Json 数组展平为值字符串

附加时将JSON展平为字符串数组

如何在postgres中将多个行值展平为串联的字符串?

如何将元组列表展平为pythonic列表

如何将Chef服务器节点解析为Rundeck服务器

如何在 JavaScript 中展平模板字符串

如何将字符串发送到Http服务器(Java)

如何将字符串(不是从表单)从HTML页面传输到服务器?

如何将ID /服务器ID保存到附件对象?

如何将FCM令牌ID发送到PHP服务器?

如何将AJAX请求中的ID列表传递给MVC中的服务器

如何将参数中的Id发送到我的服务器?

如何将React发送到Express服务器获取请求传递ID

如何将频道/服务器ID转换为其名称?

如何将nginx.org配置为渡槽服务器的代理服务器?

如何将SSRS服务器配置为仅发送报告服务器URL?

如何将Linux服务器设置为路由器

如何将字符串转换为 ID?

如何将属性字符串保存到解析服务器对象类型字段中

如何将数据(字符串)从HTTP客户端发送到服务器

如何将SQL连接字符串从服务器更改为Windows身份验证

单击按钮时如何将值或字符串从android应用程序发送到服务器

如何将数据(字符串)从html发送到服务器(节点或express)并执行某些功能?

MongoDB C#驱动程序-如何将_id存储为ObjectId但映射到字符串Id属性?

使用jquery将id的值提取为字符串

将ID转换(转换)为字符串

将包含numpy数组的元组展平为numpy数组

如何将登录页面设置为 AD 联合服务器中的主路径?