I have a parameter that is an array of objects. One of the elements in the object (‘peers’) is another array of objects. I want to dynamically extract the peers array and union / concat them and keeping the ‘vnetid’ as a reference.
param vnets array = [
{
vnetid: 0
name: '0-test-test'
addressPrefix: '10.10.74.0/22'
peers: [
{
name: '0-to-1'
peerToId: 1
}
]
subnets: [
{
name: 'GatewaySubnet'
addressPrefix: '10.10.74.0/25'
}
{
name: 'AzureFirewallSubnet'
addressPrefix: '10.10.74.128/25'
}
]
}
{
vnetid: 1
name: '1-test-test'
addressPrefix: '10.10.68.0/22'
peers: [
{
name: '1-to-0'
peerToId: 0
}
]
subnets: [
{
name: 'subnet1'
addressPrefix: '10.10.68.0/25'
}
{
name: 'subnet2'
addressPrefix: '10.10.69.0/24'
}
]
}
]
Desired new array:
param peers array = [
{
vnetid: 0
name: '0-to-1'
peerToId: 1
}
{
vnetid: 1
name: '1-to-0'
peerToId: 0
}
]
I can not find a solution. I have tried with concat, union, items and basically all the array functions. Without any luck.
2
Answers
Nice. Thanks @Thomas. Works perfectly.
You could use the map and flatten lambda functions as described here: