有一个字符串列表,这些字符串是vnet对等详细信息的输出。我需要提取一个列表中的所有源vnet名称和另一个列表的目标vnet名称。我的vnet对等名称如下
Peer =["vnet1tovnet2",
"vnet1tovnet3",
"vnet4tovnet5"]
我需要两个以下格式的列表
source=["vnet1","vnet1",vnet4"]
dest=["vnet2","vnet3","vnet5"]
如何在地形中实现这一点
您可以按如下方式执行:
locals{
Peer =["vnet1tovnet2",
"vnet1tovnet3",
"vnet4tovnet5"]
source = [for v in local.Peer: split("to", v)[0]]
dest = [for v in local.Peer: split("to", v)[1]]
}