Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added role assignment support for RGs #434

Merged
merged 6 commits into from
Jan 25, 2023

Conversation

DaFitRobsta
Copy link
Contributor

@DaFitRobsta DaFitRobsta commented Jan 21, 2023

Overview/Summary

Added support for Role Assignment at the Resource Group(s) level. Following the same pattern as Management Group(s) and Subscription(s) bicep modules. This is to address this feature request #376. AB#25949

This PR fixes/adds/changes/removes

  1. Adds support for role assignment at the Resource Group(s) level from policyAssignmentManagementGroup.bicep module.
  2. Added two modules to support granting policy assignment ID at the resource group level.
  3. Updated README.md to reflect the support for Resource Group(s) role assignment.

Breaking Changes

No breaking change, additional feature added.

Testing Evidence

Tested policyAssignmentManagementGroup.bicep module by passing in the new parameter, parPolicyAssignmentIdentityRoleAssignmentsResourceGroups, and it successfully granted policy assignment ID to contributor rights over two resource groups in a different subscription from the management group.

Tested both modules, roleAssignmentResourceGroupMany.bicep and roleAssignmentResourceGroup.bicep, following the same parameter file structure as the existing management group and subscription parameter files. Both deployments were successful.

$inputObject = @{
DeploymentName = 'alz-RoleAssignmentsDeployment-{0}' -f (-join (Get-Date -Format 'yyyyMMddTHHMMssffffZ')[0..63])
Location = 'westus3'
ManagementGroupId = 'MTB-Sandboxes'
TemplateFile = "infra-as-code/bicep/modules/roleAssignments/roleAssignmentResourceGroupMany.bicep"
TemplateParameterFile = 'infra-as-code/bicep/modules/roleAssignments/parameters/roleAssignmentResourceGroupMany.servicePrincipal.parameters.rpl.json'
}
New-AzManagementGroupDeployment @InputObject

Results:
DeploymentName : alz-RoleAssignmentsDeployment-20230120T1901489305Z
ManagementGroupId : MTB-Sandboxes
Location : westus3
ProvisioningState : Succeeded
Timestamp : 1/21/2023 2:11:17 AM

$inputObject = @{
DeploymentName = 'alz-RoleAssignmentsDeployment-{0}' -f (-join (Get-Date -Format 'yyyyMMddTHHMMssffffZ')[0..63])
ResourceGroupName = 'rg01'
TemplateFile = "infra-as-code/bicep/modules/roleAssignments/roleAssignmentResourceGroup.bicep"
TemplateParameterFile = 'infra-as-code/bicep/modules/roleAssignments/parameters/roleAssignmentResourceGroup.servicePrincipal.parameters.rpl.json'
}
New-AzResourceGroupDeployment @$inputObject

Results:
DeploymentName : alz-RoleAssignmentsDeployment-20230120T1801291965Z
ResourceGroupName : rg01
ProvisioningState : Succeeded
Timestamp : 1/21/2023 1:57:41 AM

As part of this Pull Request I have

@ghost ghost added the Needs: Triage 🔍 Needs triaging by the team label Jan 21, 2023
Copy link
Collaborator

@jtracey93 jtracey93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good @DaFitRobsta, just a couple of small bits.

Do you think it may be easier to take the full resource ID for resource groups as the array entries rather than a custom input of <sub ID>/<RG Name>?

I'm cool with not changing it just wanted to pose the question. I can see you followed the current convention we use here like subscriptions and management groups so completely fine with leaving it as I say.

@jtracey93 jtracey93 self-assigned this Jan 24, 2023
@jtracey93 jtracey93 added Area: Policy and removed Needs: Triage 🔍 Needs triaging by the team labels Jan 24, 2023
@ghost ghost removed the Needs: Author Feedback label Jan 24, 2023
@DaFitRobsta
Copy link
Contributor Author

Looking good @DaFitRobsta, just a couple of small bits.

Do you think it may be easier to take the full resource ID for resource groups as the array entries rather than a custom input of <sub ID>/<RG Name>?

I'm cool with not changing it just wanted to pose the question. I can see you followed the current convention we use here like subscriptions and management groups so completely fine with leaving it as I say.

@jtracey93, I initially considered using the resource ID of the resource group, but when setting the scope of the module, it won't accept a resource ID. It expects a subscription ID, resource Group name in the resourceGroup( ). To reduce the number of additional string functions, I decided to go with a custom input. I can definitely change it, but after reviewing the other modules, they are very similar in that they don't use an official resource ID. Let me know how you would like me to proceed.

@jtracey93
Copy link
Collaborator

jtracey93 commented Jan 24, 2023 via email

@jtracey93
Copy link
Collaborator

/azp run validateazcloud

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jtracey93
Copy link
Collaborator

/azp run e2e

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@jtracey93 jtracey93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. running tests and will merge

@jtracey93 jtracey93 merged commit 245243b into Azure:main Jan 25, 2023
@DaFitRobsta DaFitRobsta deleted the GH-Issue-376 branch January 25, 2023 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 Feature Request - RoleAssignments for PolicyAssignments on RG-Scope
2 participants