Azure ARM Template : Create Resource Group
Asked Answered
D

5

19

We are new to ARM (Azure Resource Manager) templates. While working on a template, I observed that we have to supply a resource group when deploying our template. Is it is possible to create a resource group through a template like other resources?

Dredger answered 6/12, 2017 at 9:27 Comment(0)
H
14

Now you can create a resource group using ARM templates. You can use the following template

{
  "$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": {}
}

You can run this using the Azure CLI. But you have to have the latest CLI version installed. I have version 2.0.43 installed. This includes subscription level deployments using the az deployment command.

To execute this run the following command.

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

Herne answered 6/8, 2018 at 5:32 Comment(4)
This doesn't work for me. I'm getting the foollowing (UUID redacted) {"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"NotFound","message":"{\r\n \"message\": \"No HTTP resource was found that matches the request URI 'https://management.azure.com/subscriptions/<UUID>/resourcegroups/MyResourceGroup/providers/Microsoft.Resources/resourceGroups/myResourceGroup?api-version=2018-05-01'.\"\r\n}"}]}Zloty
This solution is wrong and not working, it is using wrong schema, the solution bellow is right.Nephology
The az CLI gives a warning stating that deployment create has been deprecated and will be removed in a future release. deployment sub create should be used insteadEndsley
Please note as of today, there exist different deployment scopes indicated by $schema.Dilly
N
7

The accepted solution is wrong. Resource groups are deployed on the subscription level not on the resource group level. No wonder it is not working.

Note the $schema difference. it should be subscriptionDeploymentTemplate instead.

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "functions": [],
    "variables": {},
    "resources": [
        {
            "name": "string",
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2020-10-01",
            "location": "string",
            "tags": {},
            "properties": {
                                
            }
        }
    ],
    "outputs": {}
}
Nephology answered 28/1, 2021 at 14:51 Comment(1)
This worked for me! If you are using Azure CLI, remember to run it using az deployment sub create, so you will create new resource group inside your subscription.Cherimoya
C
5

It is now published in the microsoft docs,

az deployment create \
  -n demoEmptyRG \
  -l southcentralus \
  --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/emptyRG.json \
  --parameters rgName=demoRG rgLocation=northcentralus
Cohbath answered 15/11, 2018 at 16:55 Comment(0)
I
0

Is it is possible to create resource group through template like other resources ??

For now, we can't use arm template to create Azure resource group.

Intenerate answered 6/12, 2017 at 9:36 Comment(3)
Why?? any particular reason behind that.Dredger
By default, we will use Azure powershell or Azure CLI to create a new deployment with json file, here is the powershell command, like this: New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\Users\Desktop\jasontest2.json , in this script, we have specify the resource group.Intenerate
@BlindSniper, basically a chicken-egg situation. Resource group is created at subscription level. So deploymentParameters.json schema cant be used. Instead use subscriptionDeploymentTemplate.json schema.Dilly
S
-2

the subscriptionDeploymentTemplate.json schema must be used.

Submit answered 21/9, 2020 at 15:44 Comment(1)
try including a relevant code block or steps to help out the original poster.Orlando

© 2022 - 2024 — McMap. All rights reserved.