【问题标题】:Is it possible to concatenate a string value and a list of objects in terraform是否可以连接字符串值和 terraform 中的对象列表
【发布时间】:2022-01-12 09:21:35
【问题描述】:

下面是我的 terraform 代码,其中我有一个包含 5 个值的对象列表,是否可以将列表中的每个值与字符串值连接起来

locals{
mylist = ["aaa","bbb","ccc","ddd","eee"]
str1 = "hello"
str2 = "Data"

mergedstring =  "${local.str1},local.mylist,${local.str2}"
}

我需要以下格式的输出

hello,aaa,Data
hello,bbb,Data
hello,ccc,Data
hello,ddd,Data
hello,eee,Data

我怎样才能做到这一点?

【问题讨论】:

  • 进展如何?仍然不清楚你能做什么?
  • 成功了,谢谢

标签: list terraform concatenation


【解决方案1】:

你可以这样做:

locals{
  mylist = ["aaa","bbb","ccc","ddd","eee"]
  str1 = "hello"
  str2 = "Data"

  mergedstring = join("\n",[for v in local.mylist: "${local.str1},${v},${local.str2}"])
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2012-02-21
    • 2011-09-20
    • 1970-01-01
    • 2011-04-29
    相关资源
    最近更新 更多