How to Pass Parameters to a Bicep Template

In Azure, you can use Bicep to create and manage deployments. Bicep is a domain-specific language that allows you to automate the deployment of Azure resources.

You can use Bicep to deploy your Azure resources on-demand or as part of a release pipeline. This article will show you how to pass parameters to a Bicep deployment.

Pass Parameters

You can pass parameters to a Bicep deployment using the –parameters parameter. The –parameters parameter allows you to specify the name and value of Azure parameters. You can use the –parameters parameter to override the default values of Azure parameters. You can also use the –parameters parameter to pass additional information to your Bicep deployment.

The following example shows how to use the –parameters parameter to pass parameters to a Bicep deployment.

Define a Parameter in Template

Before passing a parameter, we need to define it in the Bicep template. In my case, it will be the name of a storage account. Below I’m defining it and setting a default value (generate a random name).

param storageaccountname string = 'ntweekly${uniqueString(utc)}'

I will use the az deployment command below to run the deployment and pass a parameter. I am overwriting the default value and creating a storage account with a specific name by passing a parameter.

az deployment group create --name deploy --template-file pass_parmaters.bicep --resource-group bicep --parameters storageaccountname=ntweekly2022


Below you can see the entire template.

param location string = resourceGroup().location
param utc string = utcNow()
param storageaccountname string = 'ntweekly${uniqueString(utc)}'

resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: storageaccountname
  location: location
  sku: {
    name: 'Standard_LRS'
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'