Deploying Bicep using Azure CLI
Deploying Bicep using Azure CLI

Azure Bicep – Deploy using Azure CLI

In previous article, we have seen what are bicep parameter files. In this article, we are going to use Azure CLI to deploy the bicep file. We will also use parameter file in this demo.

Prerequisite

Now that we want to deploy the bicep file, we will need an active Azure Subscription. If you don’t have an Azure subscription, create a free account before you begin.

Also, please make sure that you have below mentioned two extensions installed in the Visual Studio Code. These extensions are useful for authoring the bicep file.

Also, as we are going to use Azure CLI for the deployment, we will need to make sure that you have Azure CLI version 2.20.0 or later.

Then connect to Azure account using az login command. If you have multiple subscriptions, you can use az account set command to select appropriate subscription.

Required Permissions

In order to deploy a bicep file, we need to ensure that we have write permissions on the resources we are deploying. We also need to make sure that we have all permissions from Microsoft.Resources/deployments.

AZ Commands

The commands given below are the Azure CLI commands that we can use for deploying any bicep file. The command has various switches, it accepts resource group name, location and bicep file as shown in the code snippet given below.

How to pass parameters ?

There is also one more switch – parameters. This switch can be used to specify the parameter values. The parameter values can be specified either inline or via a parameter file. The code snippet given below shows various ways by which parameters can be passed.

Creating first parameters file

We have deployed a bicep file already using Visual Studio Code extension. That time we provided each parameter value separately. The bicep file is given below.

Now, let’s create the parameter file for this bicep code. It has 4 parameters, all of them are of type string. Hence writing parameter file is easy.

Now, open the bicep file in VS Code and right click on it. Select the option – Generate Parameters File – from the context menu. In the new file, add the contents given below. The code snippet given below sets the values to the three parameters from the bicep file.

Deploy the Bicep File

Both bicep file and parameter file are locally present on our computer (if you have followed the steps exactly as mentioned above). So, we can use the command given in the below code snippet.

Once this script is executed, we need to look for "provisioningState": "Succeeded" attribute from the deployment output.

I hope you find this information helpful. Let me know your thoughts.

Leave a ReplyCancel reply