← Cheatsheets
IaC

Bicep

Azure Bicep CLI commands and language syntax for deploying and managing Azure infrastructure as code.

CLI & Deployment

az bicep install
az bicep upgrade
az bicep version
az bicep build -f main.bicep
az bicep decompile -f template.json
az deployment group create -g <rg> -f main.bicep
az deployment group create -g <rg> -f main.bicep -p params.json
az deployment group create -g <rg> -f main.bicep --what-if
az deployment group validate -g <rg> -f main.bicep

Resource Declaration

resource stg 'Microsoft.Storage/storageAccounts@2023-01-01' = {...}
resource vnet 'Microsoft.Network/virtualNetworks@2023-09-01' existing = { name: 'my-vnet' }
dependsOn: [otherResource]

Parameters & Variables

param location string = resourceGroup().location
param sku string = 'Standard_LRS'
@allowed(['dev','prod']) param env string
@secure() param adminPassword string
var prefix = 'myapp-${env}'

Modules

module storage 'modules/storage.bicep' = { name: 'storageDeploy' params: {...} }
module storage 'br/public:storage/storage-account:1.0.1' = {...}
output storageId string = storage.outputs.id

Outputs & Scopes

output storageId string = stg.id
output storageUrl string = stg.properties.primaryEndpoints.blob
targetScope = 'subscription'
targetScope = 'managementGroup'

Loops & Conditions

[for i in range(0, 3): {...}]
[for item in items: {...}]
if condition
@batchSize(2)