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?
5 Answers
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
-
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}"}]}
– lorenzoApr 15, 2020 at 20:18 -
This solution is wrong and not working, it is using wrong schema, the solution bellow is right.– JanJan 28, 2021 at 14:51
-
1The
az
CLI gives a warning stating thatdeployment create
has been deprecated and will be removed in a future release.deployment sub create
should be used instead Feb 1, 2021 at 10:21
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": {}
}
-
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. Oct 17, 2022 at 7:29
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.
-
1
-
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.– Jason YeDec 6, 2017 at 9:51
the subscriptionDeploymentTemplate.json schema must be used.
-
1try including a relevant code block or steps to help out the original poster.– JaySep 21, 2020 at 17:12