This article is focused on creating an ARM template that will create a storage account resource in the resource group and will assign role at both RG (Resource Group) scope and created storage account resource level
This article is divided into following 5 sections, As it is described in the image shown below
- Fetch User Object ID
- Fetch Built-in Role ID
- Create ARM template to provision storage account
- Role assignment in ARM template
- Deploying ARM template to Azure Portal

Let’s start step by step as mentioned above, we will fetch the user object ID which will be used in deploying ARM template
- So firstly, let's fetch the user’s object id
Use the PowerShell script to fetch user’s object id by its email id.
Get-AzADUser | Where-Object { $_.UserPrincipalName -eq "[email protected]" }
This will show the user details like, DisplayName, Id, Mail, UserPrincipalName, Grab the Id and save it for further use
You can also fetch the user object Id from Azure Portal, Navigate to Azure Active Director > Users > Select the user you want to fetch the Id of > Copy the Object Id
- Similarly, we will fetch the built-in role Id using PowerShell script, for this article I will fetch the “Reader” role id but you can fetch your required role id,
Get-AzRoleDefinition -Name Reader
This script will output few of the Role details, grab the Id from the output and save it for further use
- Now it’s time to create the ARM Template which will create the Storage account and assign user with Reader role to the created storage account also, we will assign user with Reader role to the Resource group using scope.
Follow the template mentioned below for creating storage account and role assignment.
Refer Microsoft documentation to know more on ARM Template syntax and details and to know more details on role assignment
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"AAD_Object_ID": {
"metadata": {
"description": "Object ID of the User, Group or Service Principal"
},
"type": "string"
},
"Role_Definition_ID": {
"metadata": {
"description": "Identifier (GUID) of the role definition to map to service principal"
},
"type": "string"
}
},
"variables": {
"Full Role_Definition_ID": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', parameters('Role_Definition_ID'))]",
"StorageAccountName": "shrstrgacc",
"StorageAccountAssignmentName": "[concat(variables('StorageAccountName'), '/Microsoft.Authorization/', guid(concat(resourceGroup().id), variables('Full Role_Definition_ID')))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"name": "[variables('StorageAccountName')]",
"comments": "Storage account used to store VM disks",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {
"roleDefinitionId": "[variables('Full Role_Definition_ID')]",
"principalId": "[parameters('AAD_Object_ID')]"
}
},
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2017-09-01",
"name": "[guid(concat(resourceGroup().id), resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc'), variables('Full Role_Definition_ID'))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc')]"
],
"properties": {
"roleDefinitionId": "[variables('Full Role_Definition_ID')]",
"principalId": "[parameters('AAD_Object_ID')]",
"scope": "[resourceGroup().id]"
}
},
{
"type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
"apiVersion": "2017-05-01",
"name": "[variables('StorageAccountAssignmentName')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc')]"
],
"properties": {
"roleDefinitionId": "[variables('Full Role_Definition_ID')]",
"principalId": "[parameters('AAD_Object_ID')]"
}
}
],
"outputs": {}
}


Join the conversation! Your thoughts help the community grow.