Deploy Bicep File
Deploy Bicep File

Azure Bicep – How to deploy a bicep file ?

In previous two articles, we have seen how a basic bicep file looks like and we also have seen how to write conditional logic using parameters to create (or skip creating) resources. We created the bicep files, but we did not deploy them and did not check if the code really works.

Prerequisites

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.

What are available options ?

We already have seen different tools which can be installed locally to play with bicep files. We can either install extensions of Visual Studio or Visual Studio Code or otherwise we can use AZ CLI or PowerShell to deploy the bicep file.

In this article, we are going to use VS Code extension to deploy the bicep file that we already created in previous post.

VS Code Extension: To Create Bicep File

We already have seen how to install the extension. Now, let’s create a new file – first.bicep – and we will try to type some code to create a new storage account. Once we open the file, and type anything, we can see the intellisense.

For example, I tried to type storage and I got the intellisense as shown below. If I select res-storage template and press TAB, then it will insert the resource element needed to create the storage account. We just need to change or add the properties which we need. e.g. We can change name, location, sku, etc. in the code snippet.

VS Code – Bicep Extension provides intellisense

We are going to use the bicep file which we created in previous article. This script takes environment name as parameter. When the environment name is feature branch, storage account is not created.

Visualize

VS Code extension also provides an option to visualize the representations of the resources present in the bicep file. We can click on the Visualizer button from the upper right corner. This should open the Bicep Visualizer and should display the storage account as shown in the snapshot given below.

VS Code – Bicep Extension provides option to visualize resources

Deploy

We can right click on the bicep file and then select the option Deploy Bicep File from the context menu. The command palette should open and it should show option to sign in to the Azure account. Click on that option. It will open new browser instance and then sign in using your Azure account.

VS Code – Bicep Extension – Right click to see the Deploy Bicep File option from the context menu

Then provide the below mentioned inputs:

  • Deployment name, a unique name for the deployment
  • Subscription, the subscription name under which resource should be created
  • Resource Group, either create a new resource group or use an existing one
  • Select a parameter file, select none from the options.
  • Enter Parameter values (Environment Name, storageAccountType, location, storageAccountName)
  • From Create parameters file from values used in this deployment?, select No.

Once these inputs are provided, you should be able to view the details on the output console. It would take few seconds to create the resource. And that’s how we can use VS code extension to deploy the bicep file.

Now, if you try to browse the resources using Azure Portal, then you should be able to view the newly created resource.

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

Leave a Reply Cancel reply