0
votes

I am trying to create an arm template that assigns RBAC role to a group at a management group level. i am able to do it via CLI and PowerShell but can't get it working via an ARM template

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "roleDefinitionId": {
            "type": "string",
            "defaultValue": "xxxx",
            "metadata": {
                "description": "roleDefinition for the assignment - default is reader"
            }
        }
    },
    "variables": {
        "roleAssignmentName": "[guid('/', variables('xxx'), parameters('roleDefinitionId'))]"
    },
    "resources": [
        {
            "name": "[variables('roleAssignmentName')]",
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2020-04-01-preview",
            "scope": "/providers/Microsoft.Management/managementGroups/xxxx",
            "properties": {
                "mode": "Incremental",
                "roleDefinitionId": "xxx",
                "principalId": "xxxx",
                "principalType": "Group"
            }
        }
    ]
}

Does anyone know if MGMT Groups is supported, if yes what am i doing wrong?

Here is the official doc for ARM Role Assignment https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-template, it shows to do it for Subs and Resources Groups

1
Could you please tell me your error message?Jim Xu
this is one the errors i am getting validResourceType", "message": "The resource type 'managementGroups' could not be found in the namespace 'Microsoft.Management' for api version '2020-04-01-preview'. The supported api-versions are '2020-10-01,2020-05-01,2020-02-01,2019-11-01,2018-03-01-preview,2018-01-01-preview,2017-11-01-preview,2017-08-31-preview,2017-06-30-preview,2017-05-31-preview,2018-03-01-beta'." TalkingReckless
Is that you juts want to deploy the template to one group?Jim Xu
yes, tried one of the api versions listed at the top none workedTalkingReckless

1 Answers

0
votes

Remove the scope property from your resource definition...

TLDR; roleAssignments can only be deployed at the scope they are being assigned to, so the property is extraneous. Also the scope property doesn't work with managementGroup extension resources (confusing I know) which is just a point in time gap. The scope property is generally used for targeting a resource to a different scope (i.e. different from the template deployment itself) but since roleAssignments can't be retargeted you don't need it and it's going to cause a problem for you in this case.

Here's my sample (note I don't have the principalType property so it uses the default):

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.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": "b24988ac-6180-42a0-ab88-20f7382dd24c",
        "metadata": {
          "description": "roleDefinition for the assignment - default is contributor"
        }
      },
      "managementGroupName": {
        "type": "string",
        "metadata": {
          "description": "Name of the managementGroup for the roleAssignment"
        }
      }
    },
    "variables": {
      // this creates an idempotent GUID for the role assignment
      "roleAssignmentName": "[guid(parameters('managementGroupName'), parameters('principalId'), parameters('roleDefinitionId'))]"
     },
    "resources": [
      {
        "type": "Microsoft.Authorization/roleAssignments",
        "apiVersion": "2020-04-01-preview",
        "name": "[variables('roleAssignmentName')]",
        "properties": {
          "roleDefinitionId": "[tenantResourceId('Microsoft.Authorization/roleDefinitions', parameters('roleDefinitionId'))]",
          "principalId": "[parameters('principalId')]"
        }
      }
    ]
  }