是否可以在地形中连接字符串值和对象列表
Is it possible to concatenate a string value and a list of objects in terraform
下面是我的 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
我怎样才能做到这一点?
您可以按如下方式进行:
locals{
mylist = ["aaa","bbb","ccc","ddd","eee"]
str1 = "hello"
str2 = "Data"
mergedstring = join("\n",[for v in local.mylist: "${local.str1},${v},${local.str2}"])
}
下面是我的 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
我怎样才能做到这一点?
您可以按如下方式进行:
locals{
mylist = ["aaa","bbb","ccc","ddd","eee"]
str1 = "hello"
str2 = "Data"
mergedstring = join("\n",[for v in local.mylist: "${local.str1},${v},${local.str2}"])
}