Skip to content

Instantly share code, notes, and snippets.

@polatengin
Last active February 26, 2024 16:46
Show Gist options
  • Save polatengin/7f773a6fd2623fa37f3513dd79030d52 to your computer and use it in GitHub Desktop.
Save polatengin/7f773a6fd2623fa37f3513dd79030d52 to your computer and use it in GitHub Desktop.
Modular_Parameters_Design_Options

As a Bicep developer, I want to be able to import parameters from other bicepparam files, so that I can reuse parameters across multiple deployments.

In most deployment scenarios, there are parameters that are common across multiple deployments.

For example, a location, prefix/suffix, rgName parameters are often used in multiple deployments. It would be useful to be able to define common parameters in a single file, and import it into other .bicepparam files.

Design goals;

  • Allow users to split parameters to more than file
  • Good developer experience, by not forcing people to type a lot
  • Don't over complicate troubleshooting

We can use import keyword to import all or subset of parameter definitions from another bicepparam file.

Shared bicepparam file has to be marked with @shared (or something like that), so linter and syntax checker doesn't force @using statement

Files:

// shared.bicepparam
@shared

param location = 'eastus'
param sqlPwd = 'p@55w0rd!'



// module_specific.bicepparam
@shared

param location = 'westeurope'
param storageName = 'importantstorage'



// main.bicepparam
using './main.bicep'

import { sqlPwd } from './shared.bicepparam'
import { storageName } from './module_specific.bicepparam'

param location = 'westus'
param name = 'bicep'

Compiled output:

{
  "location": "westus"
  "sqlPwd": "p@55w0rd!"
  "storageName": "importantstorage"
  "name": "bicep"
}

Files:

// shared.bicepparam
@shared

param appName = 'app_1'
param sqlPwd = 'p@55w0rd!'
param sqlServerName = 'sqlServer'



// main.bicepparam
@using './main.bicep'

import { appName, sqlPwd as sqlPassword } from './shared.bicepparam'

param name = 'bicep'

Compiled output:

{
  "appName": "app_1"
  "sqlPassword": "p@55w0rd!"
  "name": "bicep"
}

Files:

// shared.bicepparam
@shared

param appName = 'app_1'
param sqlPwd = 'p@55w0rd!'
param sqlServerName = 'sqlServer'



// module_specific.bicepparam
@shared

param location = 'westeurope'
param storageName = 'importantstorage'



// main.bicepparam
@using './main.bicep'

import * from './shared.bicepparam'
import { location, storageName } from './module_specific.bicepparam'

param name = 'bicep'

Compiled output:

{
  "appName": "app_1"
  "sqlPassword": "p@55w0rd!"
  "location": "westeurope"
  "storageName": "importantstorage"
  "name": "bicep"
}

Files:

// shared.bicepparam
@shared

param appName = 'app_1'
param sqlPwd = 'p@55w0rd!'
param location = 'eastus'



// module_specific.bicepparam
@shared

param location = 'westeurope'
param storageName = 'importantstorage'



// main.bicepparam
@using './main.bicep'

import * from './shared.bicepparam'
import { location, storageName } from './module_specific.bicepparam'

Compiled output:

{
  "appName": "app_1"
  "sqlPassword": "p@55w0rd!"
  "location": "????"
  "storageName": "importantstorage"
}

With this option, we introduce a new keyword extends

bicepparam file inherits from another bicepparam file

At first, rule says you can have only one extend in a bicepparam

Files:

// shared.bicepparam
@shared

param location = 'westus'
param name = 'default_name'



// main.bicepparam
@using './main.bicep'

extends 'shared.bicepparam'

Compiled output:

{
  "location": "westus"
  "name": "default_name"
}

Files:

// shared.bicepparam
@shared

param location = 'westus'



// main.bicepparam
@using './main.bicep'

extends 'global.bicepparam' with { location }

param name = 'example_name'

Compiled output:

{
  "location": "westus"
  "name": "example_name"
}

Files:

// shared.bicepparam
@shared

param location = 'westus'
param name = 'default_name'



// main.bicepparam
@using './main.bicep'

extends 'shared.bicepparam'

param name = "overriden"

Compiled output:

{
  "location": "westus"
  "name": "????"
}
// main.bicep
param location string = 'westus'
param prefix
param name string



// shared.bicepparam
@shared

param prefix = 'project_'


// main.bicepparam
@using './main.bicep'

import * from 'shared.bicepparam'
or
extends 'shared.bicepparam'

param name = 'AKS_MODULE'
/ PROS CONS
import There is already import keyword in bicep Slightly (is it?) different behavior
import Easier to map to other languages, like js, ts, even python Behavior is off from other languages
extends No confusion with an existing behavior New keyword, new thing to learn
@majastrz
Copy link

majastrz commented Feb 1, 2024

I think it will be good to include int the proposal how using will work with this feature and how (or if) it will get inherited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment