Declarative, not good enough. Imperative, not enough. #18330
-
|
Off the top:
I'll keep it straight to the point:
Just 4 limitations that makes it impossible to dynamically deploy resources that have dependencies without just spitting every aspect of each resource in the parameter or the Bicep file. And if that's the case, what use do we have of the imperative aspect of Bicep?
I know what this sounds like, and I'm sure a lot of you feel this way one way or another or to some extent. And not to neglect all the effort put into it, but Bicep in its current state with all the extra fluff is a mild convenience over ARM templates. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
All those scenarios are actually supported using the map function: Looping over modules and resources: module someModuleLoop ...
var someVariable = map(someModuleLoop, mod => {
outputs: mod.outputs
})
// Or
var storageAccountNames = [
'${uniqueString('stAccTest')}1'
'${uniqueString('stAccTest')}2'
'${uniqueString('stAccTest')}3'
'${uniqueString('stAccTest')}4'
]
resource storageAccountLoop 'Microsoft.Storage/storageAccounts@2021-04-01' = [for name in storageAccountNames: {
name: name
location: resourceGroup().location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}]
var accountEndpoints = map(storageAccountLoop, (account) => account.properties.primaryEndpoints)
output endpoints array = accountEndpointsNested loops: var myNestedLoop = flatten(map(range(0, 5), x => map(range(1, 10), y => (x * 10 ) + y)))
//Outputs all numbers from 0 to 50 in an array
output result array = myNestedLoopAs for this:
This seems like it would be covered by using modules instead. This is just my personal preference, but I would rather have many modules doing one thing (one deploying containers, another deploying databases, another creating the cosmos DB, ...) rather than having everything in a humongous expression and template that's terrible to maintain. |
Beta Was this translation helpful? Give feedback.
-
|
main.parameters.json See attached files:
Here is the result of a |
Beta Was this translation helpful? Give feedback.
main.parameters.json
main-bicep.txt
See attached files:
main-bicep.txtis the bicep filemain.parameters.jsonis a simple parameter file represents hierarchal mapping (nested arrays) of cosmos accounts, db, and containers.Here is the result of a
WhatIfDeployment which seems to be working: