Giving access to multiple Resource Group

Prajith K 106 Reputation points
2024-02-02T12:11:26.0766667+00:00

Can you please help me how to give Contributor access in 'managedidentity1' to multiple resource group (eg : RG1, RG2, RG3)?

Azure Role-based access control
Azure Role-based access control
An Azure service that provides fine-grained access management for Azure resources, enabling you to grant users only the rights they need to perform their jobs.
686 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,849 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 4,221 Reputation points
    2024-02-02T13:54:33.4766667+00:00

    Hello @Prajith K

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    You're asking on how to give Contributor access in 'managedidentity1' to multiple resource group (eg : RG1, RG2, RG3) of Microsoft Azure.

    If the above is correct, here I will show you two ways you can do this:

    A. PowerShell:

    1. Open Azure PowerShell and make sure you are connected to your Azure account.
    2. Run the following commands to assign the Contributor role to the managed identity (managedidentity1) for each resource group (RG1, RG2, RG3):
    $resourceGroups = "RG1", "RG2", "RG3"
    $managedIdentity = "managedidentity1"
    $roleDefinition = Get-AzRoleDefinition -Name "Contributor"
    
    foreach ($resourceGroup in $resourceGroups) {
        $scope = "/subscriptions/<subscription-id>/resourceGroups/$resourceGroup"
        New-AzRoleAssignment -Scope $scope -ObjectId (Get-AzManagedIdentity -ResourceGroupName $resourceGroup -Name $managedIdentity).PrincipalId -RoleDefinitionId $roleDefinition.Id
    }
    
    

    NOTE: The <subscription-id> should be your own.

    B. Azure Portal:

    1. Navigate to the Azure Portal (https://portal.azure.com/).
    2. In each resource group, click on "Access control (IAM)" in the left-hand navigation.
    3. 1. IAM
    4. Click on "Add" to add a new role assignment.
    5. In the "Add role assignment" pane, select the role as "Contributor".
    6. 2. IAM RA
    7. In the "Assign access to" section, select "Managed Identity" and then choose your managedidentity1.
    8. Click "Save" to assign the Contributor role to the managed identity for that specific resource group.
    9. Repeat these steps for each resource group (RG1, RG2, RG3) where you want to grant Contributor access. NOTE: You might need to search for Contributor.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution. Best Regards, Sina Salam