简体   繁体   English

是否可以在 terraform 中连接字符串值和对象列表

[英]Is it possible to concatenate a string value and a list of objects in terraform

Below is my terraform code where I have a list of objects which has 5 values, is it possible to concat each value in the list with the string values下面是我的 terraform 代码,其中我有一个包含 5 个值的对象列表,是否可以将列表中的每个值与字符串值连接起来

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

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

I need the output in the following format我需要以下格式的 output

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

How can I achieve this?我怎样才能做到这一点?

You can do this as follows:您可以按如下方式执行此操作:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM