Feature request: Reusable parameter definitions across Bicep templates
- 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.**
It's not a problem, but this is related to the repetition of Bicep template parameters.
**Describe the solution you'd like**
Currently, we have a feature to export and import variables and user-defined functions, allowing us to avoid code repetition (DRY). I would like to see this extended to parameter definitions in `.bicep` templates.
I have seen many infrastructure projects where parameters are reused across different Bicep template files. This results in copying and pasting parameter definitions between templates, and when a parameter changes, it needs to be updated in all those templates. The same applies to changes to decorators such as `@allowed`.
There are probably better implementation scenarios, but I would like to start a discussion on this topic. Here is an approach that would help avoid repetition:
1. A new file extension called `.bicepextension` is introduced. In this file, you can define a set of parameters that can be extended from:
```bicepextension
@allowed([
'prd'
'acc'
'dev'
'sbx'
])
param environment string
param location string
```
2. A Bicep template uses the `extends` keyword, with an additional keyword `params` to indicate parameter extension from a `.bicepextension` file, e.g. `extends params base.bicepextension`:
```bicep
extends params base.bicepextension
param mySpecificParametersHere string
resource myResourcesHere '...' = {
location: location
name: 'my-resource-${environment}'
properties: {
something: mySpecificParametersHere
}
}
```
Or the approach to use `include ` would be something to explore too:
``` bicep
include base.bicep
param mySpecificParametersHere string
resource myResourcesHere '...' = {
location: location
name: 'my-resource-${environment}'
properties: {
something: mySpecificParametersHere
}
}
```
This approach allows users to define base parameter definitions and avoid parameter repetition. It is similar to how we can currently use parameter value sharing in Bicepparam (via the experimental feature).
### Potential duplicates
I tried to search for other feature requests similar to mine and found these two asking for somewhat the same feature, but in a different way:
https://github.com/Azure/bicep/issues/17053
https://github.com/Azure/bicep/issues/17609
I would like to hear your thoughts/opinion on this topic: @slavizh, @anthony-c-martin, @jeskew and @riosengineer.
Contributor guide
Assessment
This issue has not been assessed yet.