What needs to be changed in the arm template below in order for it to add subscription owner role to the given principal id?
The problem we are getting is that the following arm template and invocation command are assigning unintended resource group owner and NOT the desired subscription owner.
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"principalId": {
"type": "string",
"metadata": {
"description": "principalId if the user that will be given contributor access to the resourceGroup"
}
},
"roleDefinitionId": {
"type": "string",
"defaultValue": "8e3af657-a8ff-443c-a75c-2fe8c4bcb635",
"metadata": { "description": "roleDefinition for the assignment - default is owner" }
}
},
"variables": {
"roleAssignmentName": "[guid(subscription().id, parameters('principalId'), parameters('roleDefinitionId'))]"
},
"resources": [
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2020-08-01-preview",
"name": "[variables('roleAssignmentName')]",
"properties": {
"roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635')]",
"principalId": "[parameters('principalId')]"
}
}
]
}
The command we are running to invoke the above template is:
az deployment group create --resource-group myRgName --template-file myTemplateName.json --parameters principalId=<service-principal-id>
The user account that is running the preceding cli command is subscription owner and thus has permissions to assign another subscription owner.
2
Answers
The deployment you are initiating is with a resource group scope, not with a subscription scope.
For more information on the "az" command set, look at the documentation over HERE.
For more information about the role assignment, take a look at the documentation over HERE (Look at the section about "az deployment sub create")
I have used below ARM template to assign the role to Subscription.
Here is the Azure CLI command to assign the owner role to subscription.
Output:
Reference: Resource group or subscription scope