bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Allow expressions within the 'params' property of Bicep Modules

Open anwtn opened this issue 3 years ago • 2 comments

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.

anwtn avatar Oct 27 '23 07:10 anwtn

Related to (or duplicate of?) #1560

alex-frankel avatar Oct 31 '23 22:10 alex-frankel

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: ....
    ....
  }
}

Saulopv avatar May 28 '24 14:05 Saulopv