Sako
Sako

Reputation: 125

How to assign RBAC to multiple user using arm template in azure

I have two AAD Application(Service principal) and want to add RBAC to these two Application using arm template.

I tried deploying with arm template below.

    {
        "type": "Microsoft.Storage/storageAccounts/blobServices/containers/providers/roleAssignments",
        "apiVersion": "2018-09-01-preview",
        "name": "[concat(parameters('StorageAccountName'), '/default/',parameters('ContainerName'), '/Microsoft.Authorization/', parameters('roleNameGuid'))]",
        "properties": {
          "roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')]",
          "principalId": "[parameters('principalId')]"
        }      
    },
    {
        "type": "Microsoft.Storage/storageAccounts/blobServices/containers/providers/roleAssignments",
        "apiVersion": "2018-09-01-preview",
        "name": "[concat(parameters('StorageAccountName'), '/default/',parameters('ContainerName'), '/Microsoft.Authorization/', parameters('roleNameGuid'))]",
        "properties": {
          "roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')]",
          "principalId": "[parameters('principalId2')]"
        }      
    }        

When I deploy with this arm template, I got error below.

    Deployment template validation failed: 'The resource 'Microsoft.Storage/storageAccounts/MystorageAccounts/blobServices/default/containers/test/providers/Microsoft.Authorization/roleAssignments/aacd4b89-a70f-4be9-a0ba-6b8698dd7129' at line '52' and column '9' is defined multiple times in a template. Please see https://aka.ms/arm-template/#resources for usage details.'. (Code: InvalidTemplate)

Upvotes: 0

Views: 1120

Answers (2)

Marco
Marco

Reputation: 605

Wouldn't this work as well, and take away the hardcoded value of the guid?: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-string#guid

Yes it will require some input to calculate a different GUID, but you could use property iteration to change that: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#property-iteration

Upvotes: 0

Charles Xu
Charles Xu

Reputation: 31424

You need to use different names for the name option in the resource. For example, you can append a number at the end of the name to distinguish the difference.

Upvotes: 1

Related Questions