我们对ARM(Azure资源管理器)模板还不熟悉。在制作一个模板时,我注意到在部署模板时需要提供资源组。
是否可以像其他资源一样通过模板创建资源组呢?
我们对ARM(Azure资源管理器)模板还不熟悉。在制作一个模板时,我注意到在部署模板时需要提供资源组。
是否可以像其他资源一样通过模板创建资源组呢?
现在,您可以使用 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
接受的解决方案是错误的。资源组是在订阅级别上部署的,而不是在资源组级别上部署的。难怪它不起作用。
请注意 $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": {}
}
az deployment sub create
运行它,这样您就可以在订阅内创建新的资源组。 - Wojciech X该内容现已发布在Microsoft文档中,
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
New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\Users\Desktop\jasontest2.json
在此脚本中,我们已经指定了资源组。 - Jason YedeploymentParameters.json
模式。而是使用subscriptionDeploymentTemplate.json
模式。 - undefined必须使用subscriptionDeploymentTemplate.json模式。
{"code":"DeploymentFailed","message":"至少有一个资源部署操作失败。请列出详细的部署操作。请参阅https://aka.ms/DeployOperations以获取使用详细信息。","details":[{"code":"NotFound","message":"{\r\n \"message\": \"找不到与请求URI 'https://management.azure.com/subscriptions/<UUID>/resourcegroups/MyResourceGroup/providers/Microsoft.Resources/resourceGroups/myResourceGroup?api-version=2018-05-01'匹配的HTTP资源。\"\r\n}"}]}
- lorenzoaz
CLI 给出了一个警告,指出deployment create
已被弃用,并将在未来的版本中删除。应改用deployment sub create
。 - tuomastik$schema
指示。 - undefined