Why is Azure Bicep your next choice for Infrastructure As Code? | by Dave R – Microsoft Azure MVP

As a cloud engineer, you should understand the impact of Azure Bicep on your environments.

This article will cover:

  • Why Bicep is relevant
  • How Bicep will impact your environments in Azure
  • Reasons not to use Bicep

If you’re familiar with Infrastructure As Code with Azure, authoring Azure Resource Manager(ARM) templates in JSON comes with its own set of challenges.

In May 2020, at the Microsoft Build conference, a new Domain Specific Language (DSL) for deploying Azure resources declaratively was introduced to improve the ARM authoring experience and reduce the pain of writing JSON code unless you really want to.

Before we deep dive into why Bicep is relevant for you as a Cloud Engineer, let’s review some baselines to understand better why Bicep is relevant for you.

It all starts with Azure Resource Manager. Think of Azure Resource Manager as the front door for all the service-specific control plane operations that are available in Azure through an API.

Azure Resource Manager is, in fact, the underlying service layer in Azure that will help you deploy and manage resources in Azure.

You can leverage some tools and languages like Azure CLI, Azure PowerShell, SDKs, or the Azure Portal and third-party solutions to communicate with Azure Resource Manager and create, delete or update audit and tag resources in Azure.

Azure Resource Manager

In short, Azure Resource Manager will provide you with all the capabilities related to infrastructure as code, and you can execute two types of operations: control plane operations and data plane operations.

— Control plane operations are related to the way you manage resources in your subscription.

— Data plane operations allow you to access specific features exposed by a given resource.

This is an example of these operation types: You could leverage a control plane operation to provision a virtual machine and use a data plane operation to RDP to the virtual machine.

You could create scripts to provision resources to Azure or use a declarative approach for your resources through ARM templates.

ARM templates can include the definition of the infrastructure and configuration for your deployment.

The downside is that ARM templates are JSON-based, and while you can take a declarative approach to your resource provisioning when working with more complex environments, it can be a bit of a pain to manage them.

Bicep then comes in handy as it provides you with an easier syntax. ARM templates are not going away; Bicep is the new Domain Specific Language (DSL) for deploying Azure resources declaratively and sits on top of the ARM templates.

When you create a new Bicep template and deploy it, it will transpile into JSON files and then talk to Azure Resource Manager to deploy your environment in Azure.

Azure Bicep

This means we will have all the goodness and benefits from ARM templates. We will be able to create the definition of the resources and configuration for our environment in Azure with a more simple syntax.

Bicep promises a true modularization by breaking a complex template deployment into smaller module files and reference them in the main template.

While modularization is available in ARM templates through nested or linked templates, Bicep greatly simplifies how we can consume modules and call external resources.

For example, we can have a Bicep template that creates an App Service Plan and another Bicep template that creates the web application. Then we can have a main Bicep template that consumes the previous two Bicep templates as modules.

The image below shows how to make the call for the App Service Plan and the web application from the main Bicep template:

Azure Bicep — modularization

Note that Bicep is a DSL language, so the main intention is to make it easy for you to deploy and configure Azure resources; however, it will not replace any existing language.

You can check the comparison of a Bicep template and an ARM template using the Bicep Playground: https://bicepdemo.z22.web.core.windows.net/

Note that the Bicep template significantly reduces the complexity and provides a more comprehensive syntax.

Bicep is considered as an Azure-native language that will help you improve the authoring process for ARM templates and reduce some of the current pain points.

Does this mean we have to learn a new language? The short answer is yes, and you will find that Bicep is very intuitive and provides an easy transition from JSON.

So if you’re already familiar with ARM-JSON templates, you will be able to decompile them into Bicep templates through the “bicep decompile” command.

az bicep decompile --file main.json

From personal experience, If you decompile ARM-JSON templates into Bicep templates, ensure you review the definition of variables, parameters, and resource properties.

To validate your deployment, you can use the What-IF functionality or use the flag -C to have a preview of your deployment, as shown in the figure below.

Azure Bicep — Confirm the deployment

You can check more details on how to decompile ARM-JSON templates into Bicep templates in the following URL: https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/decompile?tabs=azure-cli

Optionally you can build the ARM-JSON template from the Bicep template with the command below:

bicep build main.bicep --outfile azuredeploy.json

The above command will convert your Bicep template into the ARM-JSON template.

As mentioned earlier in this article, Bicep is a specific language for your infrastructure as code deployments. While it has some advantages, it is not compatible with other cloud providers.

That said, if your organization is leveraging multiple cloud providers, Bicep might not be the right tool for cloud providers that don’t fully support Bicep as a language.

With this in mind, I encourage you to try Bicep for your infrastructure as code deployments and allow yourself to see the benefits and advantages that Bicep provides.

While Bicep is on an early stage, it supports a wide range of resources in Azure, and you can decompile your existing ARM templates and compare the syntax and ease of use.

In fact, one of the main goals of Bicep is to have the code be easy to understand at a glance and straightforward to learn.

Take a look at the Microsoft Learn Path — https://docs.microsoft.com/en-us/learn/paths/bicep-deploy/

Check how you can deploy a VM using Bicep https://blog.azinsider.net/deploy-kemp-loadmaster-in-azure-using-bicep-3b9f083997e9

.