Skip to content

Latest commit

 

History

History
82 lines (52 loc) · 3.29 KB

02-deploying-a-bicep-file.md

File metadata and controls

82 lines (52 loc) · 3.29 KB

Deploying a bicep file

Bicep files cannot yet be directly deployed via the Az CLI or PowerShell Az module. You must first compile the bicep file with bicep build then deploy via deployment commands (az deployment group create or New-AzResourceGroupDeployment).

Compile your bicep file and deploy the template to a resource group

Let's start by compiling and deploying the main.bicep file that we've been working with. You can do this via Azure PowerShell or Az CLI. For Powershell be sure to have the Az module installed to follow this tutorial by running Install-Module -Name Az -AllowClobber in an elevated Powershell session. For CLI download the correct version for your OS

Note: make sure you update your storage account name to be globally unique.

Via Azure PowerShell:

bicep build ./main.bicep # generates main.json
New-AzResourceGroup -Name my-rg -Location eastus # optional - create resource group 'my-rg'
New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName my-rg

Via Az CLI:

bicep build ./main.bicep # generates main.json
az group create -n my-rg -l eastus # optional - create resource group 'my-rg'
az deployment group create -f ./main.json -g my-rg

Deploy with parameters

In our 0.2 release, there is no new "bicep-style" of authoring a parameters file. Since the compiled bicep file is a standard JSON ARM Template, parameters can be passed to the template in the same ways you are likely already used to.

Our bicep file exposed two parameters that we can override (location and name)

Note: make sure you update your storage account name to be globally unique.

Pass parameters on the command line

CLI:

az deployment group create -f ./main.json -g my-rg --parameters location=westus name=logstorage001

PowerShell:

New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName my-rg -location westus -name logstorage001

Use a local parameters JSON file

ARM Templates support providing all of the parameters for a template via a JSON file. You can take a look at this parameters tutorial to learn how the parameters file is structured. Once you have your parameters file, you can pass it to the deployment command-line tools:

CLI:

az deployment group create -f ./main.json -g my-rg --parameters ./parameters.main.json

PowerShell:

New-AzResourceGroupDeployment -TemplateFile ./main.json -ResourceGroupName my-rg -TemplateParameterFile ./parameters.main.json

Deploy to non-resource group scopes

Bicep will compile a template that uses the resource group $schema by default:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"
  ...
}

However, you can deploy templates to any scope by specifying the targetScope property. See Resource Scopes spec for details.

Next steps

The next tutorial will walk you through the basics of using expressions like functions, string interpolation, and ternary operators in bicep.

3 - Using expressions