Allow expressions within the 'params' property of Bicep Modules
Is your feature request related to a problem? Please describe.
The current implementation in Azure Bicep appears to restrict the usage of the 'union' function exclusively to top-level variables and parameters. Attempts to utilize the 'union' function with the 'params' object of Azure Bicep modules result in the following error message:
Error BCP183: The value of the module 'params' property must be an object literal."
This limitation hinders the modularity and flexibility of Azure Bicep modules, requiring users to manually specify each parameter when combining objects.
Describe the solution you'd like Enhance Azure Bicep by enabling the 'union' function to be used seamlessly with the 'params' object of Azure Bicep modules. By allowing the 'union' function to work with the 'params' object, users can efficiently merge multiple objects within the 'params' block, thus simplifying the process of module instantiation and parameter passing. This improvement would significantly enhance the readability and maintainability of Azure Bicep code.
Approach with current code:
param my_params object = {
sku: 'free'
// other parameters...
}
var my_mod_name = 'my-great-mod'
module my_mod './my-mod/main.bicep' = {
scope: resourceGroup(rg.name)
name: '${my_mod_name}_deploy'
params: {
name: my_mod_name
location: location
tags: tags
sku: my_params.sku // This gets frustrating when the list is long.
// other parameters...
}
}
What I'd like to be able to do:
param my_params object = {
sku: 'free'
// other parameters...
}
var my_mod_name = 'my-great-mod'
module my_mod './my-mod/main.bicep' = {
scope: resourceGroup(rg.name)
name: '${my_mod_name}_deploy'
params: union({
name: my_mod_name
location: location
tags: tags
}, my_params) // Note that I would only need to reference my_params once for the union.
}
This would allow Bicep authors to not copy shared parameters for multiple module calls.
Related to (or duplicate of?) #1560
I agree, our case is a bit different but this feature would enhance the flexibility, readability and maintainability of modules.
Our use case trying to create a wrapper module:
type configType = {
cosmosDB: object
functionApp: object
....
}
param config configType
module cosmosdbModule 'cosmosdb.bicep' = {
name: '${config.cosmosDB.name}-cosmosdb-wrapper'
params: {
name: config.cosmosDB!.appName
location: config.cosmosDB.?location
model: config.cosmosDB!.dbModel
....
}
}
module functionAppModule 'function-app.bicep' = {
name: '${config.functionApp.appName}-functionApp-wrapper'
params: {
appName: config.functionApp!.appName
....
}
}
module .... '....' = {
name: ....
params: {
appName: ....
....
}
}