Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Introduction to Azure Bicep

  • July 26, 2022
  • 8 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.


Azure Bicep

Bicep is a ‘Domain Specific Language (DSL) for deploying Azure resources declaratively’. Ok so why do we need yet another way to deploy stuff in Azure? That’s a good question!

There is a huge variety of options to deploy resources in Azure. You can use:

  • The Azure portal
  • ARM template
  • Azure CLI and Azure PowerShell
  • ARM SDK
  • Terraform

The first great advantage of Bicep is the syntax. Comparing with JSON, Bicep files are more concise and easier to read for humans. The second advantage is that Bicep immediately supports all preview and GA versions for Azure services.

I will not explain in detail what is Azure Bicep (Brandon Lee wrote a great article https://www.starwindsoftware.com/blog/bicep-vs-terraform comparing Bicep vs Terraform), Bicep was well explained in this article.

Just remember that if you want to deploy resources in Multi-Cloud, Bicep is not the right tool for you, other cloud providers don’t support Bicep templates.

In this article, I will demonstrate how easy it is to use Azure Bicep to deploy a basic resource in your Azure subscription. You will never use JSON again your entire life!

Getting started

First, I advise you to install VS Code to write your Azure Bicep code. You can install the following extension to validate your code.

https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep

Bicep extension provides intellisense for the core language, so you just need to press the space bar (or CTRL + SPACE), then VS Code will list the available options or resource types.

Install Bicep

Ok you just installed VS Code + Bicep extension. Don’t forget to install the Az PowerShell module.

Az PowerShell module

Confirm that bicep extension is loaded

Confirm that bicep extension is loaded

Ok we will connect to our Azure subscription using the ‘Connect-AzAccount’ cmdlet

Connect-AzAccount

Now, we can create our first Bicep file (your file must be named using the *.bicep extension)

Get Started

Below is the code that we will use to deploy a storage account.

Below is the code that we will use to deploy a storage account

First, you must tell to Bicep that you want to define a new resource

Resource myStorAccount ‘Microsoft.Storage/’

myStorAccount is just a friendly name inside your code. It will never appear in the Azure console.

myStorAccount

Microsoft.Storage/storageAccounts@2021-09-01 is the resource type and API version of the storageAccounts that Bicep will use when it creates the resource.

Microsoft.Storage/storageAccounts@2021-09-01

Be careful, Bicep is strict about where you put line breaks. Just press CTRL + SPACE to create the squelette (e.g required-properties)

Press CTRL + SPACE to create the squelette

Repeat the same steps by pressing CTRL + SPACE for each property. As you can see, VS Code helps you to structure your Bicep code.

VS Code helps you to structure your Bicep code

You can also use parameters. Resource Manager resolves parameter values before starting the deployment operations. Wherever the parameter is used, Resource Manager replaces it with the resolved value. In my case, I use a parameter to replace the location value and to be sure that all the resources will use the same location value.

param loc string = resourceGroup().location

When you deploy your Azure Bicep file, most of time it is deployed in a resource group, so we use the RG location value.

RG location value

Now we will deploy our Bicep code using the following command:

New-AzResourceGrouDeployment -ResourceGroupName <your_RG> -TemplateFile <Bicep_File>

Deploy Bicep code

In the Azure portal, we can confirm the deployment

Azure portal

Just to really understand the power of Bicep instead of JSON complexity, below is the JSON code to create our storage account. Comparing the Bicep code, it saves time and efforts!

JSON code to create our storage account

The storage account is created in the resource group.

Storage account

Now if you want to remove the storage account, create an empty Bicep file

Remove the storage account

And run the following command:

New-AzResourceGrouDeployment -ResourceGroupName <your_RG> -TemplateFile <Bicep_File> -Mode Complete -Force -Verbose

Run the following command

Be very careful! In the « complete » mode, Resource Manager deletes resources that exist in the resource group but aren’t specified in the template. The file ‘clean.bicep’ is empty, so ARM will delete all resources in the RG.

Resource Manager

Another value is ‘Incremental’. In incremental mode, Resource Manager leaves unchanged resources that exist in the resource group but aren’t specified in the template. Resources in the template are added to the resource group.

Below is a simple but very good example from the Microsoft documentation:

Example from the Microsoft documentation

Hey! Found Nicolas’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!