Reputation: 683
In bicep, is there any good way to treat an array as a set, specifically I'd like to have an array setup in my main bicep file, say:
concat(paramArray, [
{
name: 'Foo'
value: 'FooValue'
}
])
I would like to be able to overwrite the Foo value from the param file:
param paramArray = [
{
name: 'Foo'
value: 'BazValue'
}
]
I would like to end up with the BazValue
.
Upvotes: 1
Views: 154
Reputation: 8018
To overwrite the Foo
value from the param file end up with the BazValue
in the resultant array, you can use union
and filter
operators available in Bicep which is detailed below.
Filter lambda:
Filters an array with a custom filtering function.
Union operator:
Returns a single array or object with all elements from the parameters. For arrays, duplicate values are included once.
param defaultarray array = [
{
name: 'Foo'
value: 'value'
}
]
param paramArray array = [
{
name: 'Foo'
value: 'BazValue'
}
]
var combinedArray = [for item in defaultarray: union(item, {
value: last(filter(paramArray, i => i.name == item.name)).value
})]
output resultArray array = combinedArray
Output:
References:
Upvotes: 2