close

Home

Microsoft Azure

Azure Bicep Brings Easier Infrastructure as Code to Azure Resource Management

Author avatar - Russell Smith

Russell Smith

|
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.

advertisment

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.

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 the Terraform Azure provider. 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.

advertisment

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.

advertisment

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.

Log in to save content to your profile.

Username/Email

Password

Login

Article saved!

Access saved content from your profile page. View Saved