Create Azure Resource Group With Bicep

Deploying a resource group to Azure might be a simple task using Azure CLI, The portal or Azure PowerShell but not with Bicep.

When creating a resource group with Bicep, we need to change the deployment scope to target a subscription and not a resource group.

This scenario is like the chicken and the egg case where you can create a deployment to a resource group without a resource group.

Bicep Template

The following template will create a resource group. Note that the first line of code sets the target scop to the subscription.

The code is shown below.

targetScope = 'subscription'
 resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
   name: 'MailTrain'
   location: 'southeastasia'

Because the target scope is a subscription, we also used a different Azure CLI command (sub).

az deployment sub create --location southeastasia --template-file  file.bicep

About Azure Bicep

The Resource Manager template language Azure Bicep enables you to deploy Azure resources declaratively. It’s a domain-specific language, which implies it was created specifically to deploy Azure resources. Bicep is only used to create Resource Manager templates.

Bicep is designed to be simple to understand and learn, regardless of your prior experience with other programming languages. Bicep templates can use all resource types, API versions, and property values.