bicep icon indicating copy to clipboard operation
bicep copied to clipboard

[Extendable Param Files] Multiple Extends Statements

Open stephaniezyen opened this issue 1 year ago • 5 comments

Add support for multiple extends statements in an extendable .bicepparam file

stephaniezyen avatar Jul 09 '24 16:07 stephaniezyen

+1

slavizh avatar Jul 10 '24 05:07 slavizh

Any hopes of this being added?

mrkesu avatar Dec 02 '24 09:12 mrkesu

Design for Multiple extends statements in bicepparam files

TL;DR bicepparam files can include multiple extends statements, allowing to inherit parameters from several base parameter files. Each extends statements specifies one bicepparam file, and parameters from all extended files are merged in order. Local parameters override inherited ones. If conflicting parameter values are found across extended files, the compiler will report an error to ensure explicit resolution. This feature enables flexible, modular, and reusable parameter configurations with minimal syntax changes.

Syntax

Two syntax options;

Multiple extends lines

One extends statement per base file.

Allow the bicepparam file to have multiple extends lines, each with exactly one file path:

extends 'base.bicepparam'
extends 'global.bicepparam'

param environment = 'dev'
param enableMonitoring = false

Single extends statement with array of base files

extends [ 'base.bicepparam', 'global.bicepparam' ]

param environment = 'dev'
param enableMonitoring = false

Semantic Resolution

For each extends statements:

  • Load and recursively resolve its parameters and its own extends.
  • Merge all extended parameter sets.
  • Detect cycles across all extends to prevent infinite loops.

Parameter Merging and Conflict Handling

  • Merge parameters from extended files in the order they are declared.
  • Detect if the same parameter is defined in multiple extended files with different values.
  • Conflict resolution options:
    • Fail compilation with a clear error message asking the user to override explicitly.
    • Optionally, allow a CLI flag to relax this to “last wins”.

Override Priority

  • Local parameters defined in the entry point bicepparam file override all extended parameters.

Backward Compatibility

  • Current users with one extends line continue to work without change.
  • Multiple extends lines are additive.

Example

extends [ 'base.bicepparam' , 'security.bicepparam' ]

param environment = 'prod'
param enableMonitoring = true
  • Parameters from base.bicepparam and security.bicepparam are merged (in that order).
  • Local parameters override merged ones.

Benefits

  • Minimal syntax change - very intuitive to users already familiar with single extends.
  • Easy to add multiple bases without changing existing files.
  • Explicit ordering of inheritance via multiple extends lines.

polatengin avatar May 21 '25 18:05 polatengin

One year since this suggestion was made so that means we're only 2 years away from this getting implemented, yay! Exciting!

mrkesu avatar Jul 28 '25 07:07 mrkesu

Hey @mrkesu , can you share some scenarios/use-cases that you need multiple extends statements in bicepparam files?

polatengin avatar Nov 17 '25 16:11 polatengin