简体   繁体   中英

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

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

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}"])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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