简体   繁体   中英

Azure ARM Template : Create Resource Group

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?

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

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

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

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.

必须使用 subscriptionDeploymentTemplate.json 架构。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM