Azure ARM模板:创建资源组

Bli*_*per 7 azure azure-rm-template azure-resource-group

我们是ARM模板的新手.在模板上工作时,我发现我们必须在部署ARM模板时提供资源组.是否有可能像其他资源一样通过模板创建资源组?

Kas*_*oda 7

现在,您可以使用ARM模板创建资源组.您可以使用以下模板

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

您可以使用Azure CLI运行此命令.但是您必须安装最新的CLI版本.我安装了2.0.43版.这包括使用该命令的订阅级别部署az deployment.

要执行此操作,请运行以下命令.

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


Jan*_*Jan 6

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.

请注意 $schema 的差异。它应该是subscriptionDeploymentTemplate

{
    "$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": {}
}
Run Code Online (Sandbox Code Playgroud)


Saj*_*ran 5

它现在发布在微软文档中

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
Run Code Online (Sandbox Code Playgroud)