Reading a template
| ARM JSON section | Bicep keyword | Plain meaning |
|---|---|---|
parameters | param | Questions answered at deploy time (name, size). defaultValue makes one optional; allowedValues limits choices. |
variables | var | Values worked out inside the file (a name built from a prefix) |
resources | resource | The things to build: type, apiVersion, name, location, properties |
dependsOn | usually not needed | Build order. In Bicep, referring to another resource by its symbolic name sets the order automatically. |
outputs | output | Values returned when done (an IP address, a connection string) |
[resourceGroup().location] | resourceGroup().location | Functions; JSON wraps them in square brackets |
// main.bicep
param location string = resourceGroup().location // optional, has a default
param storageName string // required, no default
resource sa 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageName
location: location
sku: { name: 'Standard_LRS' }
kind: 'StorageV2'
}
output blobEndpoint string = sa.properties.primaryEndpoints.blob
You, the admin: four ways to get and use a template
- From a wizard: on the Review + create tab click Download a template for automation. You get the JSON and a parameters file instead of clicking Create.
- From an existing thing: Resource group › Automation › Export template. Verbose, but a start. Convert to Bicep with
az bicep decompile -f template.json. - From a past run: Resource group › Deployments › pick one › Template.
- Deploy: Home › search "Deploy a custom template" › Build your own template in the editor, or
az deployment group create -g RG1 -f main.bicep -p storageName=contoso01, orNew-AzResourceGroupDeployment -ResourceGroupName RG1 -TemplateFile main.bicep. Deployment scopes also exist for subscription, management group and tenant level (az deployment sub createetc.).
Two settings that matter
- Mode Incremental (default): add what is missing, update what differs, ignore everything else in the group.
- Mode Complete: make the group look exactly like the file. Anything in the group that is not in the file is deleted. Dangerous; the exam loves it.
A failed deployment does not undo what it already built; read the error under Deployments, fix the file, run again (idempotent, so already-correct resources are untouched). --what-if previews changes without applying them. Parameter files (main.parameters.json or main.bicepparam) let one template serve dev and prod.