Allow expressions within the 'params' property of Bicep Modules
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**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.
Contributor guide
Research direction
The issue names no source files or tests; begin by locating validation for a module's params property and handling of union expressions. Done means module params accept the shown union(...) object expression, with coverage for the example behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100