Using Bicep to create ARM Templates

I worked on both ARM templates and Terraforms for deploying Azure resources. ARM is Microsoft default Infrastructure as code language,  is extremely powerful.whereas Terraform  uses Hashicorp Configuration Language (HCL)  to build/configure infrastructure, Each section of the configuration file is human-readable and describes the desired resources to be implemented.

On September 8th (My birthday 😊) , Bicep was announced through a tweet by Mark Russinovich  and also invited for open source contribution. It appears Bicep is going to simplify usage of ARM templates , resource declaration can be done using human readable format. I want to build actual biceps but not yet ready to go to gym due to pandemic, I decided to stick with Bicep files for now 😊

Note: Bicep is not production ready, more breaking changes will be announced by the end of the year (2020). If you are interested in contributing to project please visit

What is Bicep (as mentioned on Github repo)?

Bicep is a Domain Specific Language (DSL) for deploying Azure resources declaratively. It aims to drastically simplify the authoring experience with a cleaner syntax and better support for modularity and code re-use. Bicep is a transparent abstraction over ARM and ARM templates, which means anything that can be done in an ARM Template can be done in bicep (outside of temporary known limitations). All resource typesapiVersions, and properties that are valid in an ARM template are equally valid in Bicep on day one.

Bicep compiles down to standard ARM Template JSON files, which means the ARM JSON is effectively being treated as an Intermediate Language (IL). Bicep is source-to-source compiler, Source code written in Bicep is compiled to equivalent ARM code(template), Similar to Babel , how it  converts ES5/6 to JavaScript.

Getting started.

We need two components to  build and Run Bicep Files

  • Bicep CLI (required)
  • Bicep VS Code Extension



# Create the install folder
$installPath = "$env:USERPROFILE\.bicep"
$installDir = New-Item -ItemType Directory -Path $installPath -Force
$installDir.Attributes += 'Hidden'
# Fetch the latest Bicep CLI binary
(New-Object Net.WebClient).DownloadFile("", "$installPath\bicep.exe")
# Add bicep to your PATH
$currentPath = (Get-Item -path "HKCU:\Environment" ).GetValue('Path', '', 'DoNotExpandEnvironmentNames')
if (-not $currentPath.Contains("%USERPROFILE%\.bicep")) { setx PATH ($currentPath + ";%USERPROFILE%\.bicep") }
if (-not $env:path.Contains($installPath)) { $env:path += ";$installPath" }
# Verify you can now access the 'bicep' command.
bicep --help
# Done!


# Fetch the latest Bicep CLI binary
curl -Lo bicep
# Mark it as executable
chmod +x ./bicep
# Add bicep to your PATH (requires admin)
sudo mv ./bicep /usr/local/bin/bicep
# Verify you can now access the 'bicep' command
bicep --help
# Done!


# Fetch the latest Bicep CLI binary
curl -Lo bicep
# Mark it as executable
chmod +x ./bicep
# Add Gatekeeper exception (requires admin)
sudo spctl --add ./bicep
# Add bicep to your PATH (requires admin)
sudo mv ./bicep /usr/local/bin/bicep
# Verify you can now access the 'bicep' command
bicep --help

Install the Bicep VS Code extension

  • Download the latest version of the extension
  • Open VSCode, and in the Extensions tab, select the options (…) menu in the top right corner and select ‘Install from VSIX’. Provide the path to the VSIX file you downloaded.

Let’s build some Biceps (files)

Create a empty file main.Bicep in VS code and compile it by running bicep build main.bicep.
And then the magic happens , A skeleton ARM JSON template file gets generated, Bicep Cli converts Bicep code into ARM code.

  "$schema": "",
  "contentVersion": "",
  "parameters": {},
  "functions": [],
  "variables": {},
  "resources": [],
  "outputs": {}

There are four main components in the resource declaration.

  1. Resource  
  2. Name- identifier to reference resource with in Bicep file
  3. Type – Type of resource
  4. Properties – resource properties
Resource bicepstg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
    name: 'azsrini-stg' 
    location: 'eastus'
    kind: 'Storage'
    sku: {
        name: 'Standard_LRS'

Now Compile the bicep file using bicep build main.bicep , ARM code is generated for storage resource in the Json file, At this point, I can deploy it like any other ARM template using the standard command line tools (az deployment or New-AzResourceGroupDeployment)

Adding parameters.

param location string = 'eastus'

resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = {
    name: azsrini-stg
    location: location
    kind: 'Storage'
    sku: {
        name: 'Standard_LRS'

Emitting Outputs to be passed to a script or another template

Deploying Bicep File.

Bicep files cannot yet be directly deployed via the Az CLI or PowerShell Az module. You must first compile the bicep file with bicep build then deploy ARM Json via deployment commands (az deployment or New-AzResourceGroupDeployment).

Azure PowerShell:

bicep build ./main.bicep # generates main.json
New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName azsrini-rg

Deploy with parameters

Our bicep file has one parameter that we can override (location) during the deployment

New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName azsrini-rg -location westus

ARM templates also support passing a Parameter file.

New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName azsrini-rg -TemplateParameterFile ./parameters.main.json


Bicep is not production ready and is actively developed, more features will be coming soon. Please follow Bicep Github library for updates, releases and More Feature.

Microsoft Ignite is next week , Sep 22 – 24, This year(2020) it’s completely virtual and Free, Attend to learn about Product Announcement and Roadmaps, and a oppurtunity to meet some legends in the industry.

Useful links :

Thank you
Srinivasa Avanigadda

Using Bicep to Create ARM Templates.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s