Hello,
I’m trying convert source object:
local.map_auto_ip
{
"appliance" = {}
"mgmt" = {
"tfbs11is" = "10.130.0.1"
"tfcp10" = "10.130.0.2"
"tfds20" = "10.130.0.3"
"tfhv01centos7kvm" = "10.130.0.4"
}
"provisioning" = {
"tfcp10" = "10.134.0.1"
"tfhv01centos7kvm" = "10.134.0.2"
}
"public" = {}
"storage" = {
"tfbs11is" = "10.131.0.1"
"tfds20" = "10.131.0.2"
"tfhv01centos7kvm" = "10.131.0.3"
}
}
Into this, but I’m trying many variants how to do this but unfortunately can’t find solution…
Of course public and appliance could be used too. Number of addresses can be different.
It is possible to do this?
{
"tfbs11is" = {
"mgmt" = "10.130.0.1"
"storage" = "10.131.0.1"
},
"tfcp10" = {
"mgmt" = "10.130.0.2"
"provisioning" = "10.134.0.1"
},
"tfds20" = {
"mgmt" ="10.130.0.3"
"storage" = "10.131.0.2"
}
"tfhv01centos7kvm" = {
"mgmt" = "10.130.0.4"
"provisioning" = "10.134.0.2"
"storage" = "10.131.0.3"
}
}
PS. The last my try is, but result is wrong… And I don’t understand why ‘k’ key not used…
[ for k,v in local.map_auto_ip: {for x,y in v: x=>{k = y} } ]
[
{},
{
"tfbs11is" = {
"k" = "10.130.0.1"
}
"tfcp10" = {
"k" = "10.130.0.2"
}
"tfds20" = {
"k" = "10.130.0.3"
}
"tfhv01centos7kvm" = {
"k" = "10.130.0.4"
}
},
{
"tfcp10" = {
"k" = "10.134.0.1"
}
"tfhv01centos7kvm" = {
"k" = "10.134.0.2"
}
},
{},
{
"tfbs11is" = {
"k" = "10.131.0.1"
}
"tfds20" = {
"k" = "10.131.0.2"
}
"tfhv01centos7kvm" = {
"k" = "10.131.0.3"
}
},
]
Okay… this one looks better but I need to unite by keys: tfbs11is, tfcp10 …
[ for k, v in local.map_auto_ip: {for x, y in v: x=>{"${k}" = y} } ]
[
{},
{
"tfbs11is" = {
"mgmt" = "10.130.0.3"
}
"tfcp10" = {
"mgmt" = "10.130.0.4"
}
"tfds20" = {
"mgmt" = "10.130.0.5"
}
"tfhv01centos7kvm" = {
"mgmt" = "10.130.0.6"
}
},
{
"tfcp10" = {
"provisioning" = "10.134.0.3"
}
"tfhv01centos7kvm" = {
"provisioning" = "10.134.0.4"
}
},
{},
{
"tfbs11is" = {
"storage" = "10.131.0.3"
}
"tfds20" = {
"storage" = "10.131.0.4"
}
"tfhv01centos7kvm" = {
"storage" = "10.131.0.5"
}
},
]