Insight Tech APAC Blog Logo

Introducing the .bicepparam file

stephentulp
December 6, 2023

6 minutes to read

Bicep Advent Calendar

Introduction

In this blog post, we will learn about the new .bicepparams extension that can be used to replace the existing .json parameter files. We will also take a look at the Bicepconfig.json file and how it can be used to customize the development experience for Bicep templates.

Bicep Parameters File

The Bicep parameters file is a new file extension that can be used to create an external parameter file using Bicep to extend the parameters in the Bicep template. This is a great way to separate the parameters from the Bicep template and removed the need to have .json for the parameter file. A Bicep parameters file has the file extension of .bicepparam.

In the same way Bicep templates simplify the authoring experience for ARM templates, Bicep parameters files simplify the authoring experience over the traditional .json parameter files.

NOTE - The Bicep parameters file is only supported in Bicep version 0.18.4 or newer, and Azure CLI version 2.47.0 or newer.

A .bicepparam parameters file is made up of the following structure:

using '<path>/<file-name>.bicep'

param <first-parameter-name> = <first-value>
param <second-parameter-name> = <second-value>

If take a look at the main.bicep from yesterday, and create a dedicated parameters file for this, we would get:

using 'main.bicep' // This is the file path to the Bicep template

param location = 'australiaeast'
param tags = {
  applicationName: 'SAP Landing Zone'
  owner: 'Platform Team'
  criticality: 'Tier1'
  costCenter: '1234'
  contactEmail: 'test@test.com'
  dataClassification: 'Internal'
}

You can also define and use variables. Bicep CLI version 0.21.X or higher is required for using variables in .bicepparam file. Here are some examples:

using 'main.bicep' // This is the file path to the Bicep template

param location = 'australiaeast'
param tags = {
  applicationName: 'SAP Landing Zone'
  owner: 'Platform Team'
  criticality: 'Tier1'
  costCenter: '1234'
  contactEmail: 'test@test.com'
  dataClassification: 'Internal'
}

var resourceGroupPrefix = 'arg'
var locationPrefix = 'syd'
var lzPrefix = 'sap'
var environmentPrefix = 'prd'

Parameter Types

The following example shows the formats of different parameter types: string, integer, boolean, array, and object.

using 'main.bicep'

param exampleString = 'test string'
param exampleInt = 2 + 2
param exampleBool = true
param exampleArray = [
  'value 1'
  'value 2'
]
param exampleObject = {
  property1: 'value 1'
  property2: 'value 2'
}

Generating the Parameters File

We have two automated options to generate the parameters file:

  • Use the az bicep param generate command
az bicep generate-params --file main.bicep --output-format bicepparam --include-params all

The command creates a Bicep parameters file named main.bicepparam, the parameter file contains all parameters in the Bicep file, whether configured with default values or not.

  • Use within Visual Studio Code
  1. Open the Bicep template file in VSCode
  2. Press Ctrl+Shift+P to open the command palette
  3. Type Bicep: Generate Parameter File and press Enter
  4. Select the output format Bicep Parameters File (.bicepparam)
  5. Select the parameters to include in the parameter file (all, required, or none)
  6. The parameter file is generated in the selected path
  7. The parameter file is automatically associated with the Bicep template file

An example .bicepparam file can be found in the in the Insight Bicep Advent Calendar GitHub Repository

The Bicepconfig file

The Bicepconfig.json file is a new file that can be used to customize the development experience for Bicep templates. The Bicep extension for Visual Studio Code supports intellisense for your bicepconfig.json file. Use the intellisense to discover available properties and values.

Bicepconfig

Some of the properties that can be configured in the Bicepconfig.json file are:

An example Bicepconfig.json file is outlined below.

{
  "analyzers": {
    "core": {
      "enabled": true,
      "verbose": true,
      "rules": {
        "adminusername-should-not-be-literal": {
          "level": "error"
        },
        "no-hardcoded-env-urls": {
          "level": "error"
        },
        "no-unnecessary-dependson": {
          "level": "error"
        },
        "no-unused-params": {
          "level": "error"
        },
        "no-unused-vars": {
          "level": "error"
        },
        "outputs-should-not-contain-secrets": {
          "level": "error"
        },
        "prefer-interpolation": {
          "level": "error"
        },
        "secure-parameter-default": {
          "level": "error"
        },
        "simplify-interpolation": {
          "level": "error"
        },
        "protect-commandtoexecute-secrets": {
          "level": "error"
        },
        "use-stable-vm-image": {
          "level": "error"
        },
        "explicit-values-for-loc-params": {
          "level": "off"
        },
        "no-hardcoded-location": {
          "level": "error"
        },
        "no-loc-expr-outside-params": {
          "level": "error"
        },
        "max-outputs": {
          "level": "error"
        },
        "max-params": {
          "level": "error"
        },
        "max-resources": {
          "level": "error"
        },
        "max-variables": {
          "level": "error"
        },
        "artifacts-parameters": {
          "level": "error"
        },
        "no-unused-existing-resources": {
          "level": "error"
        },
        "prefer-unquoted-property-names": {
          "level": "error"
        },
        "secure-secrets-in-params": {
          "level": "error"
        },
        "use-stable-resource-identifiers": {
          "level": "error"
        },
        "secure-params-in-nested-deploy": {
          "level": "error"
        },
        "use-recent-api-versions": {
          "level": "off"
        },
        "use-resource-id-functions": {
          "level": "error"
        }
      }
    }
  }
}

An example .bicepconfig.json file can be found in the in the Insight Bicep Advent Calendar GitHub Repository

Conclusion

Today we have learned about the new .bicepparam file extension and how it can be used to create an external parameter file using Bicep to extend on the parameters in the Bicep template. We also learned about the Bicepconfig.json file and how it can be used to customize the development experience for Bicep templates.

Further Reading

Some further reading on the topics covered in this post: