Skip to content

Feature request: Reusable parameter definitions across Bicep templates #18225

@johnlokerse

Description

@johnlokerse

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:
@allowed([
	'prd'
	'acc'
	'dev'
	'sbx'
])
param environment string

param location string
  1. 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:
extends params base.bicepextension

param mySpecificParametersHere string

resource myResourcesHere '...' = {
	location: location
	name: 'my-resource-${environment}'
	properties: {
		something: mySpecificParametersHere
	}
}

Or the approach to use include <path to bicep file> would be something to explore too:

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:
#17053
#17609

I would like to hear your thoughts/opinion on this topic: @slavizh, @anthony-c-martin, @jeskew and @riosengineer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions