Create parameters files for Bicep deployment

Rather than passing parameters as inline values in your script, you can use a Bicep parameters file with the .bicepparam file extension or a JSON parameters file that contains the parameter values. This article shows how to create parameters files.

Note

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

A single Bicep file can have multiple Bicep parameters files associated with it. However, each Bicep parameters file is intended for one particular Bicep file. This relationship is established using the using statement within the Bicep parameters file.

You can compile Bicep parameters files into JSON parameters files to deploy with a Bicep file. See build-params. You can also decompile a JSON parameters file into a Bicep parameters file. See decompile-params.

Parameters file

A parameters file uses the following format:

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

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

You can use the using statement with Bicep file, ARM JSON templates, Bicep modules, and template specs. For example:

using './main.bicep'
...
using './azuredeploy.json'
...
using 'br/public:storage/storage-account:3.0.1'
...
using 'br:myacr.azurecr.io/bicep/modules/storage:v1'
...
using 'ts:00000000-0000-0000-0000-000000000000/myResourceGroup/storageSpec:1.0'
...

For more information, see the using statement.

You can use expressions with the default value. For example:

using 'main.bicep'

param storageName = toLower('MyStorageAccount')
param intValue = 2 + 2

You can reference environment variables as parameter values. For example:

using './main.bicep'

param intFromEnvironmentVariables = int(readEnvironmentVariable('intEnvVariableName'))

You can 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'

var storagePrefix = 'myStorage'
param primaryStorageName = '${storagePrefix}Primary'
param secondaryStorageName = '${storagePrefix}Secondary'
using './main.bicep'

var testSettings = {
  instanceSize: 'Small'
  instanceCount: 1
}

var prodSettings = {
  instanceSize: 'Large'
  instanceCount: 4
}

param environmentSettings = {
  test: testSettings
  prod: prodSettings
}

It's worth noting that the parameters file saves parameter values as plain text. For security reasons, this approach isn't recommended for sensitive values such as passwords. If you must pass a parameter with a sensitive value, keep the value in a key vault. Instead of adding the sensitive value to your parameters file, use the getSecret function to retrieve it. For more information, see Use Azure Key Vault to pass secure parameter value during Bicep deployment.

Parameter type formats

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'
}

Use Bicep syntax to declare objects and arrays.

File name

Bicep parameters file has the file extension of .bicepparam.

To deploy to different environments, you create more than one parameters file. When you name the parameters files, identify their use such as development and production. For example, use main.dev.bicepparam and main.prod.bicepparam to deploy resources.

Define parameter values

To determine how to define the parameter names and values, open your Bicep file. Look at the parameters section of the Bicep file. The following examples show the parameters from a Bicep file called main.bicep.

@maxLength(11)
param storagePrefix string

@allowed([
  'Standard_LRS'
  'Standard_GRS'
  'Premium_LRS'
])
param storageAccountType string = 'Standard_LRS'

In the parameters file, the first detail to notice is the name of each parameter. The parameter names in your parameters file must match the parameter names in your Bicep file.

using 'main.bicep'

param storagePrefix
param storageAccountType

The using statement ties the Bicep parameters file to a Bicep file. For more information, see using statement.

After typing the keyword param in Visual Studio Code, it prompts you the available parameters and their descriptions from the linked Bicep file:

Screenshot of the prompt of the available parameters.

When hovering over a param name, you can see the parameter data type and description.

Screenshot of the parameter data type and description.

Notice the parameter type. The parameter types in your parameters file must use the same types as your Bicep file. In this example, both parameter types are strings.

using 'main.bicep'

param storagePrefix = ''
param storageAccountType = ''

Check the Bicep file for parameters with a default value. If a parameter has a default value, you can provide a value in the parameters file, but it's not required. The parameters file value overrides the Bicep file's default value.

using 'main.bicep'

param storagePrefix = '' // This value must be provided.
param storageAccountType = '' // This value is optional. Bicep will use default value if not provided.

Check the Bicep's allowed values and any restrictions such as maximum length. Those values specify the range of values you can provide for a parameter. In this example, storagePrefix can have a maximum of 11 characters and storageAccountType must specify an allowed value.

Note

Your parameters file can only contain values for parameters that are defined in the Bicep file. If your parameters file contains extra parameters that don't match the Bicep file's parameters, you receive an error.


Generate parameters file

To generate a parameters file, you have two options: either through Visual Studio Code or by using the Bicep CLI. Both methods allow you to derive the parameters file from a Bicep file. From Visual Studio Code, See Generate parameters file. From Bicep CLI, see Generate parameters file.

Build Bicep parameters file

From Bicep CLI, you can build a Bicep parameters file into a JSON parameters file. For more information, see Build parameters file.

Deploy Bicep file with parameters file

Azure CLI

From Azure CLI, you can pass a parameter file with your Bicep file deployment.

With Azure CLI version 2.53.0 or later, and Bicep CLI version 0.22.X or higher, you can deploy a Bicep file by utilizing a Bicep parameter file. With the using statement within the Bicep parameters file, there's no need to provide the --template-file switch when specifying a Bicep parameter file for the --parameters switch.

az deployment group create \
  --name ExampleDeployment \
  --resource-group ExampleGroup \
  --parameters storage.bicepparam

You can use inline parameters and a location parameters file in the same deployment operation. For example:

az deployment group create \
  --name ExampleDeployment \
  --resource-group ExampleGroup \
  --parameters storage.bicepparam \
  --parameters storageAccountType=Standard_LRS

For more information, see Deploy resources with Bicep and Azure CLI.

Azure PowerShell

From Azure PowerShell, pass a local parameters file using the TemplateParameterFile parameter.

New-AzResourceGroupDeployment `
  -Name ExampleDeployment `
  -ResourceGroupName ExampleResourceGroup `
  -TemplateFile C:\MyTemplates\storage.bicep `
  -TemplateParameterFile C:\MyTemplates\storage.bicepparam

You can use inline parameters and a location parameters file in the same deployment operation. For example:

New-AzResourceGroupDeployment `
  -Name ExampleDeployment `
  -ResourceGroupName ExampleResourceGroup `
  -TemplateFile C:\MyTemplates\storage.bicep `
  -TemplateParameterFile C:\MyTemplates\storage.bicepparam `
  -storageAccountType Standard_LRS

For more information, see Deploy resources with Bicep and Azure PowerShell. To deploy .bicep files you need Azure PowerShell version 5.6.0 or later.

Parameter precedence

You can use inline parameters and a local parameters file in the same deployment operation. For example, you can specify some values in the local parameters file and add other values inline during deployment. If you provide values for a parameter in both the local parameters file and inline, the inline value takes precedence.

It's possible to use an external JSON parameters file, by providing the URI to the file. External Bicep parameters file is not currently supported. When you use an external parameters file, you can't pass other values either inline or from a local file. All inline parameters are ignored. Provide all parameter values in the external file.

Parameter name conflicts

If your Bicep file includes a parameter with the same name as one of the parameters in the PowerShell command, PowerShell presents the parameter from your Bicep file with the postfix FromTemplate. For example, a parameter named ResourceGroupName in your Bicep file conflicts with the ResourceGroupName parameter in the New-AzResourceGroupDeployment cmdlet. You're prompted to provide a value for ResourceGroupNameFromTemplate. To avoid this confusion, use parameter names that aren't used for deployment commands.

Next steps