Tutorial: Use Azure Quickstart templates for Azure Resource Manager Bicep development
Azure Quickstart templates is a repository of community contributed JSON templates. You can use the sample templates in your Bicep development. In this tutorial, you find a website resource definition, decompile it to Bicep, and add it to your Bicep file. It takes about 12 minutes to complete.
Note
This article contains Bicep examples. Bicep is currently in preview. For more information, see Project Bicep.
Prerequisites
We recommend that you complete the tutorial about exported templates, but it's not required.
You must have Visual Studio Code with the Bicep extension, and either Azure PowerShell or Azure CLI. For more information, see Bicep tools.
Review Bicep file
At the end of the previous tutorial, your Bicep file had the following contents:
@minLength(3)
@maxLength(11)
param storagePrefix string
@allowed([
'Standard_LRS'
'Standard_GRS'
'Standard_RAGRS'
'Premium_LRS'
])
param storageSKU string = 'Standard_LRS'
param location string = resourceGroup().location
param appServicePlanName string = 'exampleplan'
var uniqueStorageName = '${storagePrefix}${uniqueString(resourceGroup().id)}'
resource stg 'Microsoft.Storage/storageAccounts@2019-04-01' = {
name: uniqueStorageName
location: location
sku: {
name: storageSKU
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
}
}
resource appPlan 'Microsoft.Web/serverfarms@2016-09-01' = {
name: appServicePlanName
location: location
sku: {
name: 'B1'
tier: 'Basic'
size: 'B1'
family: 'B'
capacity: 1
}
kind: 'linux'
properties: {
perSiteScaling: false
reserved: true
targetWorkerCount: 0
targetWorkerSizeId: 0
}
}
output storageEndpoint object = stg.properties.primaryEndpoints
This Bicep file works for deploying storage accounts and app service plans, but you might want to add a website to it. You can use pre-built templates to quickly discover the JSON required for deploying a resource. Before Azure Quickstart templates offer Bicep samples, you can use conversion tools to convert JSON templates to Bicep files.
Find template
Currently, the Azure Quickstart templates only provide JSON templates. There are tools you can use to decompile JSON templates to Bicep templates.
In Search, enter deploy linux web app.
Select the tile with the title Deploy a basic Linux web app. If you have trouble finding it, here's the direct link.
Select Browse on GitHub.
Select azuredeploy.json. This is the template you can use.
Select Raw, and then make a copy of the URL.
Browse to https://bicepdemo.z22.web.core.chinacloudapi.cn/, Select Decompile, and then provide the raw template URL.
Review the Bicep template. In particular, look for the
Microsoft.Web/sites
resource.There are a couple of important Bicep features to note in this new resource if you have worked on JSON templates.
In ARM JSON templates, you must manually specify resource dependencies with the dependsOn property. The website resource depends on the app service plan resource. With Bicep, if you reference any property of the resource by using the symbolic name, the dependsOn property is automatically added.
You can easily reference the resource ID from the symbolic name of the app service plan (appServicePlanName.id) which will be translated to the resourceId(...) function in the compiled JSON template.
Revise existing Bicep file
Merge the decompiled quickstart template with the existing Bicep file. Same as what you did in the previous tutorial, update the resource symbolic name, and the resource name to match your naming convention.
@minLength(3)
@maxLength(11)
param storagePrefix string
@allowed([
'Standard_LRS'
'Standard_GRS'
'Standard_RAGRS'
'Premium_LRS'
])
param storageSKU string = 'Standard_LRS'
param location string = resourceGroup().location
param appServicePlanName string = 'exampleplan'
@minLength(2)
@description('Base name of the resource such as web app name and app service plan.')
param webAppName string
@description('The Runtime stack of current web app.')
param linuxFxVersion string = 'php|7.0'
var uniqueStorageName = '${storagePrefix}${uniqueString(resourceGroup().id)}'
var webAppPortalName = '${webAppName}${uniqueString(resourceGroup().id)}'
resource stg 'Microsoft.Storage/storageAccounts@2019-04-01' = {
name: uniqueStorageName
location: location
sku: {
name: storageSKU
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
}
}
resource appPlan 'Microsoft.Web/serverfarms@2016-09-01' = {
name: appServicePlanName
location: location
sku: {
name: 'B1'
tier: 'Basic'
size: 'B1'
family: 'B'
capacity: 1
}
kind: 'linux'
properties: {
perSiteScaling: false
reserved: true
targetWorkerCount: 0
targetWorkerSizeId: 0
}
}
resource site 'Microsoft.Web/sites@2020-06-01' = {
name: webAppPortalName
location: location
kind: 'app'
properties: {
serverFarmId: appPlan.id
siteConfig: {
linuxFxVersion: linuxFxVersion
}
}
}
output storageEndpoint object = stg.properties.primaryEndpoints
The web app name needs to be unique across Azure. To prevent having duplicate names, the webAppPortalName
variable has been updated from var webAppPortalName_var = '${webAppName}-webapp'
to var webAppPortalName = '${webAppName}${uniqueString(resourceGroup().id)}'
.
Deploy Bicep file
Use either Azure CLI or Azure PowerShell to deploy a Bicep template.
If you haven't created the resource group, see Create resource group. The example assumes you've set the bicepFile variable to the path to the Bicep file, as shown in the first tutorial.
To run this deployment cmdlet, you must have the latest version of Azure PowerShell.
New-AzResourceGroupDeployment `
-Name addwebapp `
-ResourceGroupName myResourceGroup `
-TemplateFile $bicepFile `
-storagePrefix "store" `
-storageSKU Standard_LRS `
-webAppName demoapp
Note
If the deployment failed, use the verbose
switch to get information about the resources being created. Use the debug
switch to get more information for debugging.
Clean up resources
If you're moving on to the next tutorial, you don't need to delete the resource group.
If you're stopping now, you might want to clean up the resources you deployed by deleting the resource group.
- From the Azure portal, select Resource group from the left menu.
- Enter the resource group name in the Filter by name field.
- Select the resource group name.
- Select Delete resource group from the top menu.
Next steps
You learned how to use a quickstart template for your Bicep development. In the next tutorial, you add tags to the resources.