Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bicep Refreshed
# Bicep CLI
bicep build azuredeploy.bicep
# Azure CLI
az bicep build --file azuredeploy.bicep
Get-ChildItem -Path **/*.bicep -Recurse | ForEach-Object {
az bicep build --file $_.FullName
}
# ARM template file
az deployment group create \
--name <deployment_name> \
--resource-group <resource_group_name> \
--template-file azuredeploy.json \
--parameters @azuredeploy.parameters.json
# Bicep file
az deployment group create \
--name <deployment_name> \
--resource-group <resource_group_name> \
--template-file azuredeploy.bicep \
--parameters @azuredeploy.parameters.json
# Bicep CLI
bicep decompile azuredeploy.json
# Azure CLI
az bicep decompile --file azuredeploy.json
// Without decorators
param storageAccountSku string {
allowd: [
'Standard_GRS'
'Standard_LRS'
]
default: 'Standard_LRS'
}
// With decorators
@allowed([
'Standard_GRS'
'Standard_LRS'
])
param storageAccountSku string = 'Standard_LRS'
param location = resourceGroup().location
resource webapp 'Microsoft.Web/sites@2020-12-01' = if (location == 'koreacentral') {
...
}
param webapps array = [
'dev'
'test'
'prod'
]
// Use array only
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for name in webapps: {
name: 'my-webapp-${name}'
...
}]
// Use both array and index
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for (name, index) in webapps: {
name: 'my-webapp-${name}-${index + 1}'
...
}]
// Use range
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for i in range(0, 10): {
name: 'my-webapp-${index + 1}'
...
}]
// storageAccount.bicep
param resourceName string
param location string = resourceGroup().location
resource st 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: resourceName
location: location
...
}
output id string = st.id
output name string = st.name
// consumptionPlan.bicep
param resourceName string
param location string = resourceGroup().location
resource csplan 'Microsoft.Web/serverfarms@2020-12-01' = {
name: resourceName
location: location
...
}
output id string = csplan.id
output name string = csplan.name
// functionApp.bicep
param resourceName string
param location string = resourceGroup().location
param storageAccountId string
param storageAccountName string
param consumptionPlanId string
resource fncapp 'Microsoft.Web/sites@2020-12-01' = {
name: resourceName
location: location
...
properties: {
serverFarmId: consumptionPlanId
...
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccountId, '2021-02-01').keys[0].value}'
}
...
]
}
}
}
output id string = fncapp.id
output name string = fncapp.name
// azuredeploy.bicep
param resourceName string
param location string = resourceGroup().location
module st './storage-account.bicep' = {
name: 'StorageAccountProvisioning'
params: {
name: resourceName
location: location
}
}
module csplan './consumption-plan.bicep' = {
name: 'ConsumptionPlanProvisioning'
params: {
name: resourceName
location: location
}
}
module fncapp './function-app.bicep' = {
name: 'FunctionAppProvisioning'
params: {
name: resourceName
location: location
storageAccountId: st.outputs.id
storageAccountName: st.outputs.name
consumptionPlanId: csplan.outputs.id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment