← Back to blog

Getting Started with Bicep for Azure

6 min read
AzureBicepIaCTutorial

Getting Started with Bicep for Azure

Clicking through the Azure portal works fine when you have a handful of resources. Once you get beyond that, things start to drift. Somebody changes a setting in one environment but not another, there is no record of what changed or why, and rebuilding anything from scratch becomes a guessing game.

Infrastructure as Code fixes this. You define your resources in files, version them in Git, and deploy them through pipelines. Bicep is Microsoft's language for doing this in Azure.

Why Bicep instead of ARM templates?

ARM templates have been around for years but they are JSON, and writing JSON by hand is painful. Bicep compiles down to ARM but the syntax is much cleaner:

  • About half the code compared to the equivalent ARM JSON
  • Proper intellisense and validation in VS Code
  • You can split things into modules and reuse them
  • No state file to manage, unlike Terraform. Deployments go straight to the Azure Resource Manager API

Your first Bicep deployment

Here is a simple storage account:

bicep
param location string = resourceGroup().location
param storageAccountName string

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

Deploy it with the Azure CLI:

bash
az deployment group create \
  --resource-group my-rg \
  --template-file main.bicep \
  --parameters storageAccountName=mystorageacct

Hooking it into CI/CD

The real benefit is when you deploy Bicep through a pipeline. With GitHub Actions you can validate templates on PR and deploy on merge to main. Everyone can see what infrastructure changes are going in and when.

When Terraform makes more sense

Bicep only works with Azure. If you are running multi-cloud or your team already uses Terraform, it might not be worth switching. Plenty of teams use both: Bicep for Azure-specific stuff and Terraform for anything that spans multiple providers.

Where to go next

  • Install the Bicep CLI and the VS Code extension
  • Pick a resource you built manually and write a Bicep template for it
  • Set up a GitHub Actions workflow to deploy on merge
  • Look into Bicep modules once you have a few templates going