0
0
Azurecloud~5 mins

Bicep as ARM simplification in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Deploying resources in Azure can be complex using raw ARM templates because they use long JSON files. Bicep simplifies this by using a cleaner, easier language that compiles into ARM templates, making deployments faster and less error-prone.
When you want to deploy Azure resources with simpler and more readable code than raw ARM JSON.
When you need to reuse parts of your infrastructure code with modules.
When you want to avoid manual JSON editing and reduce syntax errors.
When you want to quickly test and deploy infrastructure changes in Azure.
When you want to maintain infrastructure as code with better tooling support.
Config File - main.bicep
main.bicep
param location string = 'eastus'

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: 'examplestorageacct'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {}
}

output storageAccountId string = storageAccount.id

This Bicep file defines a storage account resource in Azure.

param location: sets the Azure region for deployment.

resource storageAccount: declares a storage account with a name, location, SKU, and kind.

output storageAccountId: outputs the resource ID after deployment.

Commands
This command compiles the Bicep file into an ARM JSON template that Azure understands for deployment.
Terminal
az bicep build --file main.bicep
Expected OutputExpected
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "defaultValue": "eastus" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2022-09-01", "name": "examplestorageacct", "location": "[parameters('location')]", "sku": { "name": "Standard_LRS" }, "kind": "StorageV2", "properties": {} } ], "outputs": { "storageAccountId": { "type": "string", "value": "[resourceId('Microsoft.Storage/storageAccounts', 'examplestorageacct')]" } } }
--file - Specifies the Bicep file to compile
This command deploys the compiled ARM template to the specified Azure resource group.
Terminal
az deployment group create --resource-group example-rg --template-file main.json
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/mainDeployment", "name": "mainDeployment", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorageacct" } } } }
--resource-group - Specifies the target Azure resource group
--template-file - Specifies the ARM template file to deploy
This command checks the status and details of the deployment to confirm it succeeded.
Terminal
az deployment group show --resource-group example-rg --name mainDeployment
Expected OutputExpected
{ "name": "mainDeployment", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorageacct" } } } }
--resource-group - Specifies the resource group of the deployment
--name - Specifies the deployment name to query
Key Concept

If you remember nothing else from this pattern, remember: Bicep lets you write simple, clean code that turns into ARM templates for easy Azure resource deployment.

Common Mistakes
Trying to deploy the Bicep file directly without compiling it first.
Azure only accepts ARM JSON templates for deployment, so the Bicep file must be compiled first.
Always run 'az bicep build --file main.bicep' to create the ARM template before deploying.
Using an incorrect resource group name or one that does not exist during deployment.
Deployment fails if the resource group does not exist or is misspelled.
Create the resource group first with 'az group create' or verify the name before deploying.
Not specifying the location parameter or using an invalid Azure region.
The deployment will fail or resources will be created in an unintended region.
Set a valid Azure region like 'eastus' in the parameter or use the default.
Summary
Write infrastructure code in Bicep for simpler and cleaner Azure resource definitions.
Compile Bicep files into ARM JSON templates using 'az bicep build'.
Deploy the compiled ARM template to Azure with 'az deployment group create'.
Check deployment status with 'az deployment group show'.