Lesson 2 of 5 ARM Templates and Bicep Files

Reading Bicep Files

Bicep is a simpler language that compiles to ARM templates. This lesson explains Bicep declarations and how they map to JSON.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe Bicep parameters, variables, resources, modules and outputs.
  • Explain implicit dependencies and decorators.
  • Map common ARM template constructs to Bicep.

Bicep declarations

A Bicep file (.bicep) contains declarations instead of JSON sections. targetScope sets the scope (resourceGroup by default). param declares parameters with a type and optional default; decorators such as @allowed(), @minLength(), @description() and @secure() add constraints. var declares variables, resource declares a resource with a symbolic name and a type with API version, module deploys another Bicep file, and output returns values. The example below is the Bicep equivalent of the template in the previous topic.

@minLength(3)
@maxLength(24)
param storageName string

@allowed([
  'Standard_LRS'
  'Standard_GRS'
])
param skuName string = 'Standard_LRS'

param location string = resourceGroup().location

resource stg 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: storageName
  location: location
  sku: { name: skuName }
  kind: 'StorageV2'
  properties: { minimumTlsVersion: 'TLS1_2' }
}

output blobEndpoint string = stg.properties.primaryEndpoints.blob
Match the pairs

Bicep keywords

Exam skills 3.1.1

Match each Bicep keyword or decorator with what it declares.

Log in to try this activity Interactive activities are free with an account.

Differences from JSON

Bicep removes much of JSON's ceremony. Strings use single quotes and interpolation ('${vmName}-nic') instead of concat(). Properties of other resources are referenced through the symbolic name (stg.id, vnet.properties.subnets[0].id), and such a reference creates an implicit dependency, so explicit dependsOn is rarely needed. There is no contentVersion, and the Azure CLI and PowerShell compile Bicep to JSON automatically when deploying. The table below compares the main constructs.

ConceptARM template (JSON)Bicep
Parameter"parameters": { "name": { "type": "string" } }param name string
Variable"variables": { "x": "..." }var x = '...'
Reference a parameter[parameters('name')]name
Concatenate[concat('a', parameters('b'))]'a${b}'
DependencydependsOnImplicit through symbolic references
Secure parameter"type": "securestring"@secure() param p string

The following diagram shows a Bicep file excerpt and how it is evaluated for a production environment.

Reading a Bicep file. With env set to prod, the conditional expression makes skuName Standard_GRS, so the storage account is geo-redundant. The subnet references nsg.id in its properties, which creates an implicit dependency: Bicep deploys the NSG before the subnet without any dependsOn.
The file is abbreviated.
True or false

Bicep compared with JSON

Exam skills 3.1.1 · 3.1.3

Check how Bicep differs from ARM JSON templates.

Log in to try this activity Interactive activities are free with an account.
Worked example

Interpreting a Bicep file

A Bicep file declares param env string with @allowed(['dev', 'prod']), a variable var skuName = env == 'prod' ? 'Standard_GRS' : 'Standard_LRS', and a storage account that uses skuName. A subnet resource references nsg.id in its properties. Which redundancy does a deployment with env set to prod use, and how is the subnet's dependency on the NSG declared?

The conditional (ternary) expression evaluates to Standard_GRS for prod. The reference to nsg.id creates an implicit dependency, so Bicep deploys the NSG before the subnet without any dependsOn. Deploying with env set to test would fail validation because of the @allowed decorator.

Check yourself

How does Bicep know that a subnet must be deployed after its NSG?

Show answer

The subnet references the NSG's symbolic name (for example nsg.id), which creates an implicit dependency.

Exam Tips

Remember for the exam

  • Bicep compiles to an ARM template; both deploy the same way.
  • Symbolic references create implicit dependencies.
  • Decorators such as @allowed and @secure constrain parameters.
  • String interpolation replaces concat().