我正在尝试使用以下命令部署 ARM 模板以从 azure cloud shell 创建资源组和存储帐户,
新 AzSubscriptionDeployment
-Location "westus3"
-名称“MyResourceGroupDeployment” -TemplateFile "/home/mary/clouddrive/main-template.json"
-TemplateParameterFile“/home/mary/clouddrive/variables.json”
但是出现以下错误,
New-AzDeployment: 9:29:13 PM - Error: Code=InvalidScope; Message=The request contains resources that must be deployed at a resource group scope but a different scope was found. Make sure to specify a resource group scope similar to: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}'New-AzDeployment: 9:29:13 PM - Error: Code=InvalidScope; Message=Resource: '/subscriptions/19713d52-d81f-4a02-9bd2-01f2a7d436e8/providers/Microsoft.Storage/storageAccounts/stppuxdatatestwus' contains an invalid scope, expected a resource group scope but found a subscription scope: '/subscriptions/19713d52-d81f-4a02-9bd2-01f2a7d436e8'.New-AzDeployment: The deployment validation failed
请确认在同一模板中与其他资源一起创建资源组是否正确?
在单个 ARM 模板中部署资源组和存储帐户。
要使用单个 ARM 模板创建资源组和存储帐户,可以通过在
nested
部署块中定义存储帐户范围的方式来实现,以便存储帐户应部署在资源组下而不是订阅下。
更新了ARM模板:
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2021-04-01",
"location": "[parameters('location')]",
"name": "[parameters('resourceGroupName')]"
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "nestedStorageDeployment",
"resourceGroup": "[parameters('resourceGroupName')]",
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups', parameters('resourceGroupName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-09-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {}
}
]
}
}
}
],
"parameters": {
"resourceGroupName": {
"type": "string"
},
"location": {
"type": "string"
},
"storageAccountName": {
"type": "string"
}
}
}
变量.json:
{
"resourceGroupName": {
"value": "vksbResourceGroup"
},
"location": {
"value": "westus3"
},
"storageAccountName": {
"value": "testcccsstorageaccount"
}
}
命令:
New-AzSubscriptionDeployment -Location "westus3" -Name "vkkResourceGroupDeployment" -TemplateFile "main-template.json" -TemplateParameterFile "variable.json"
部署:
参考: