Microsoft Azure

Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management

Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management

Azure Project Bicep, or just Bicep as Microsoft sometimes refers to it, is a new domain-specific language (DSL) for deploying cloud resources using infrastructure as code. If this sounds like Azure Resource Manager (ARM) templates, then you’d be right. ARM templates can now be authored in Bicep or JSON.

Infrastructure as code and ARM templates

ARM templates allow you to deploy resources in Azure using infrastructure as code. Instead of explicitly telling Azure how to deploy a resource, like you might do with Azure CLI or PowerShell, infrastructure as code lets you define a deployment in a declarative syntax. You describe each resource in a deployment but without instructions about how to deploy the resources.

Using infrastructure as code has several benefits. ARM templates are idempotent, meaning that if you redeploy a template, you get the same result, and any existing resources aren’t duplicated. ARM can deploy resources in parallel, without you having to manage the orchestration in your code.

And there are a host of other benefits, like the ability to preview the results using a ‘what-if’ tool, testing templates before deployment, and continuous integration/continuous development (CI/CD) integration with Azure DevOps and GitHub.

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

The problem with JSON

JSON is difficult to read. So, Bicep was developed as an alternative to JSON for creating ARM templates. And to be honest, JSON ARM templates have put some people off using infrastructure as code in Azure, looking to third-party solutions instead like Terraform. Terraform also has the advantage of working across different cloud platforms.

Azure Bicep offers a clearer syntax than JSON along with better support for modularity and code reuse. And just in case you were wondering, Bicep is open source. And it works transparently with ARM, so you don’t need to update anything or change your settings in Azure.

Getting started with Azure Bicep

To get started with Bicep, you’ll need to have Visual Studio Code installed on your development PC. And you should install the Azure Bicep extension for Visual Studio Code. You’ll also need either the latest versions of Azure CLI or Azure PowerShell installed locally.

Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management
Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management (Image Credit: Russell Smith)

Here is what a storage account resource looks like defined using Bicep in an ARM template. In the first line of code, we give the resource a symbolic name (storageAccount), which is never displayed in Azure. And then the resource type and API version are declared: Microsoft.Storage/[email protected] And Microsoft.Storage/storageAccounts defines the resource type.

resource storageAccount 'Microsoft.Storage/[email protected]' = {
  name: 'petristorage'
  location: 'eastus'
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

When you are laying out your Bicep template, the extension for Visual Studio Code understands the resources you are deploying and lists the available properties and values that are possible to use. Once you’ve finished creating the template, you can deploy it using PowerShell or Azure CLI.

Azure Bicep Playground

The Azure Bicep Playground, lets you decompile your existing ARM JSON templates to Bicep. In the image below, you can see a Bicep template in the left pane and the equivalent JSON code in the right pane.

Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management
Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management (Image Credit: Russell Smith)

Bicep addresses DevOps issues with ARM JSON templates

Because Bicep is a domain-specific language, I think we can assume that it’s not designed to be extended to other platforms, like AWS. At least for now, Bicep looks like it’s just for Azure deployments. But who knows, Microsoft might extend it in the future. But regardless of the Azure-only limitation, Bicep looks like it addresses many of the issues that DevOps had with JSON templates.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (2)

2 responses to “Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management”

  1. I’ve moved all of our projects over to Bicep in the past 6 months and so far it has been largely an enormous improvement, but you do need to take into account that Bicep is compiled into the old JSON format and so a number of the old pitfalls for those projects still apply. Most notoriously properties with array values, like a vnet’s subnet list, are _still_ rebuilt each time they are applied no matter what strategy you select.

Leave a Reply

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.