Creating New Resource Groups using Azure Resource Manager (ARM) Templates

Creating New Resource Groups using Azure Resource Manager (ARM) Templates

Up till recently, we were not able to create a Resource Group using ARM templates. We always deployed an ARM template on top of an existing Resource Group. But now you are able to create a new Resource Group using ARM Templates.

You can now use Microsoft.Resources/resourceGroups provider in your ARM templates. So, the ARM template looks something like this.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "rgLocation": {
      "type": "string",
      "defaultValue": "Southeast Asia"
    },
    "rgName": {
      "type": "string",
      "defaultValue": "myResourceGroup"
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2018-05-01",
      "location": "[parameters('rgLocation')]",
      "name": "[parameters('rgName')]"
    }
  ],
  "outputs": {}
}

Once you have created the ARM template you need to deploy it. We could use New-AzureRmResourceGroupDeployment PowerShell command or az group deployment create Azure CLI command to deploy it. The problem is you need to provide a resource group name to both these commands. But we are trying to create a resource group.

To deploy the above template, you need to do a Subscription Level Deployment. You can do this using the latest version of Azure CLI. It supports subscription level deployments. I have installed v2.0.43 of the Azure CLI and then you can execute the following CLI command.

az deployment create --name <deployment_name> --location <resource_location> --template-file .\azuredeploy.json

Once the deployment complete, in the Azure Portal you should be able to see a new Resource Group created with the name you defined in the ARM template.

You Might Also Like
Comments