Bicep Parameter Files Are Here And You Should Switch

Whilst we’ve been using Bicep files for a while now to create infrastructure as code, we’ve been stuck using the same JSON parameter files we had been using with ARM templates to be able to pass in parameters to our Bicep code. Well, no more! We now have a Bicep parameter file, the .bicepparam file, which allows us to use Bicep syntax and offers several benefits.

All of that said, the JSON parameter files still work, so why should you switch? Let’s take a look.

Simplified Syntax

The Bicep parameter file follows the same path as Bicep templates and greatly reduces the complexity of how we declare parameters. Below is a JSON parameter file:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "StorageAccountName": {
      "value": "storageaccount1"
    },
    "VnetName": {
      "value": "network01"
    }
  }
}

Now let’s look at the same file, but converted to a Bicep parameters file.

using 'main.bicep'

param StorageAccountName = 'storageaccount1'
param VnetName = 'network01'

This makes parameter files much simpler to create and to read and edit.

Expression Support

You can use any of the Bicep expressions in a parameters file. For example, we could use the substring function to ensure our Storage Account name is short enough:

param StorageAccountName = substring('storageaccount', 0, 11)

Load Parameters from Environment Variables

We can now load parameters directly from environment variables. This is a great feature if you want to be able to programmatically vary a value without needing to edit the actual file.

param StorageAccountName = readEnvironmentVariable('STORAGE_ACCOUNT_NAME')

Parameters read from environment variables always come in as strings, you can cast them to other types if needed:

param StorageAccountCount = int(readEnvironmentVariable('STORAGE_ACCOUNT_COUNT'))

Better Intellisense

You’ll notice that the bicep parameters file has a using statement that points to the Bicep template that it is going to be used for. This links the two together and means that you get better Intellisense/autocomplete when editing the parameters file using VS Code and the Bicep extension. The editor will tell you what parameters are missing and offer autocompletion to create them.

autocomplete

Parameter File Generation

If you’re using VS Code with the Bicep plugin you can have it autogenerate the parameters file for you. Just right-click on on your Bicep template and go to Generate Parameters File, you can then select the type (Bicep or JSON) and whether to generate parameters for all values or only required ones.

Generate File

You can also generate parameter files using the Azure CLI.