Reading Time: 2 minutes

One of the essential features of Bicep is the ability to provide parameter values during runtime. In this blog post, we will discuss how to provide parameter values during runtime when deploying Bicep templates.

But first, let’s take a step back and discuss what parameters are in Bicep templates. Parameters are values that are defined in the Bicep code and can be used to customize the deployment of Azure resources. They are similar to function parameters in programming languages. When deploying Bicep templates, you can provide the values for these parameters during runtime.

To provide parameter values during runtime, you need to use Azure CLI or PowerShell. The following steps show how to deploy a Bicep template and provide parameter values using the Azure CLI:

  1. Open the Azure CLI and sign in to your Azure account.
  2. Navigate to the directory where your Bicep file is located.
  3. Run the following command to deploy the Bicep template
# Example - Provide a single parameter during runtime

az deployment group create --resource-group <resource-group-name> --template-file <bicep-file-name> --parameters <parameter-name>=<parameter-value>

# Example - Provide multiple parameters during runtime

az deployment group create --resource-group <resource-group-name> --template-file <bicep-file-name> --parameters <parameter-name>=<parameter-value> <parameter-name>=<parameter-value>

Replace <resource-group-name> with the name of your resource group, <bicep-file-name> with the name of your Bicep file, and <parameter-name> and <parameter-value> with the name and value of your parameter, respectively. For example, if your parameter is called location and you want to set its value to eastus, the command would look like this:

# Example - Provide a single parameter during runtime

az deployment group create --resource-group myResourceGroup --template-file myBicepFile.bicep --parameters location=eastus

# Example - Provide multiple parameters during runtime

az deployment group create --resource-group myResourceGroup --template-file myBicepFile.bicep --parameters location=eastus name=stg01

4.Wait for the deployment to complete.

That’s it! You have successfully provided parameter values during runtime when deploying a Bicep template using the Azure CLI.

You can also provide parameter values using PowerShell.

Here some examples:

# Example - Provide a single parameter during runtime

New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <bicep-file-name> -TemplateParameterObject @{<parameter-name>=<parameter-value>}

# Example - Provide multiple parameters during runtime

New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <bicep-file-name> -TemplateParameterObject @{<parameter-name>=<parameter-value>;<parameter-name>=<parameter-value>}

Replace <resource-group-name> with the name of your resource group, <bicep-file-name> with the name of your Bicep file, <parameter-name> with the name of your parameter, and <parameter-value> with the value of your parameter. For example, if your parameter is called location and you want to set its value to eastus, the command would look like this:

# Example - Provide a single parameter during runtime

New-AzResourceGroupDeployment -ResourceGroupName myResourceGroup -TemplateFile myBicepFile.bicep -TemplateParameterObject @{location="eastus"}

# Example - Provide multiple parameters during runtime

New-AzResourceGroupDeployment -ResourceGroupName myResourceGroup -TemplateFile myBicepFile.bicep -TemplateParameterObject @{location="eastus";name="stg01"}

In conclusion, providing parameter values during runtime is a crucial feature of Bicep templates. It allows you to customize the deployment of Azure resources and automate the deployment process. With the use of Azure CLI or PowerShell, you can easily provide parameter values when deploying Bicep templates.

Thanks for reading my blog!

Feel free to drop your comment or question below.