我正在尝试创建一个具有VM的ARM模板,我希望VM对其他资源组中的Container Registry分配AcrPull
角色。我正在将范围属性设置为ACR的ID(我是从https://resources.azure.com中获得的)。
{
"apiVersion": "2017-09-01",
"type": "Microsoft.Authorization/roleAssignments",
"name": "[guid(resourceGroup().id, 'stuff')]",
"properties": {
"roleDefinitionId": "[variables(parameters('builtInRoleType'))]",
"principalId": "[reference(variables('vmResourceId'), '2017-12-01', 'Full').identity.principalId]",
"scope": "[concat(/subscriptions/abc123-x123-4bef-84ec-1716390f231b/resourceGroups/someresroucegroupname/providers/Microsoft.ContainerRegistry/registries/someacrname"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
]
}
我不断收到错误:
"The request to create role assignment '694829aa-cee5-4fe3-bf94-3ae372c14f26' is not valid. Role
assignment scope '/subscriptions/abc123-x123-4bef-84ec-1716390f231b' must match the scope specified on
the URI '/subscriptions/abc123-x123-4bef-84ec-1716390f231b/resourcegroups/myresourcegroupname'.
这甚至有可能吗?
您需要像这样嵌套模板调用来包装它:
{
"type": "Microsoft.Resources/deployments",
"name": "nested-role-assignment",
"apiVersion": "2017-05-10",
"resourceGroup": "your_resource_group",
"subscriptionId": "your_subscription_id",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2017-09-01",
"type": "Microsoft.Authorization/roleAssignments",
"name": "[guid(resourceGroup().id, 'stuff')]",
"properties": {
"roleDefinitionId": "[variables(parameters('builtInRoleType'))]",
"principalId": "[reference(variables('vmResourceId'), '2017-12-01', 'Full').identity.principalId]",
"scope": "[concat(/subscriptions/abc123-x123-4bef-84ec-1716390f231b/resourceGroups/someresroucegroupname/providers/Microsoft.ContainerRegistry/registries/someacrname"
}
}
]
}
}
}
因此,有效地将它直接部署到ACR所在的资源组。