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
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 instead –
Endsley $schema
. –
Dilly 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": {}
}
az deployment sub create
, so you will create new resource group inside your subscription. –
Cherimoya 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
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.
New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\Users\Desktop\jasontest2.json
, in this script, we have specify the resource group. –
Intenerate deploymentParameters.json
schema cant be used. Instead use subscriptionDeploymentTemplate.json
schema. –
Dilly the subscriptionDeploymentTemplate.json schema must be used.
© 2022 - 2024 — McMap. All rights reserved.
{"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