admin管理员组文章数量:1399251
Given these two variables:
var businessUnits = ['bu1', 'bu2']
var environments = ['dev', 'prd']
I want to create new array with these values:
['bu1-dev', 'bu1-prd', 'bu2-dev', 'bu2-prd']
How to achieve this in bicep?
Given these two variables:
var businessUnits = ['bu1', 'bu2']
var environments = ['dev', 'prd']
I want to create new array with these values:
['bu1-dev', 'bu1-prd', 'bu2-dev', 'bu2-prd']
How to achieve this in bicep?
Share Improve this question edited Mar 26 at 19:20 Thomas 30k6 gold badges98 silver badges141 bronze badges Recognized by Microsoft Azure Collective asked Mar 26 at 18:05 joostmnljoostmnl 11 Answer
Reset to default 0You can use lambda functions map
and reduce
to merge/combine arrays.
See my original answer for more details: How to loop over multiple arrays for a resource
param businessUnits array = ['bu1', 'bu2']
param environments array = ['dev', 'prd']
output buEnvs array = reduce(
businessUnits,
[],
(cur, next) => concat(cur, map(environments, environment => '${next}-${environment}'))
)
As per MARCH 2025 this won't work with variables in bicep current state as variables are not typed. If you upgrade to latest bicep version (>= v0.34.1) There is an experimental feature for typed variabes.
You would need to create bicepconfig.json
config file (see documentation):
{
"experimentalFeaturesEnabled": {
"typedVariables": true
}
}
Then you would be able to use the same approach with variables:
var businessUnits array = ['bu1', 'bu2']
var environments array = ['dev', 'prd']
output buEnvs array = reduce(
businessUnits,
[],
(cur, next) => concat(cur, map(environments, environment => '${next}-${environment}'))
)
本文标签: azureHow can i combine two arrays in bicepStack Overflow
版权声明:本文标题:azure - How can i combine two arrays in bicep? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744133668a2592293.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论