Skip to content

Commit 9a5cf9c

Browse files
committed
revert variables
1 parent 85c92d0 commit 9a5cf9c

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

.github/tests/cleanup-scripts/cleanup_resouce_groups.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ $subscriptions = @(
2323
"0aeefd1c-62c7-4071-91ad-925899603976"
2424
)
2525

26+
$roleDefinitionsFilter = "Azure Landing Zones"
27+
2628
$managementGroups | ForEach-Object -Parallel {
2729
$managementGroupFilter = $using:managementGroupFilter
2830
$managementGroup = $_
@@ -40,6 +42,37 @@ $managementGroups | ForEach-Object -Parallel {
4042
Write-Host "Deleting management group: $($childManagementGroup.name) under parent: $managementGroup"
4143
az account management-group delete --name $childManagementGroup.name
4244
} -ThrottleLimit 10
45+
46+
$roleDefinitionsFilter = $using:roleDefinitionsFilter
47+
$roleDefinitions = az role definition list --management-group $managementGroup | ConvertFrom-Json | Where-Object { $_.name -like "*$roleDefinitionsFilter*" -and $_.assignableScopes -contains "/providers/Microsoft.Management/managementGroups/$managementGroup" }
48+
$roleDefinitions | ForEach-Object -Parallel {
49+
$managementGroup = $using:managementGroup
50+
$roleDefinition = $_
51+
52+
$roleAssignments = az role assignment list --role $roleDefinition.name --management-group $managementGroup | ConvertFrom-Json
53+
$roleAssignments | ForEach-Object -Parallel {
54+
$managementGroup = $using:managementGroup
55+
$roleDefinition = $using:roleDefinition
56+
$roleAssignment = $_
57+
Write-Host "Deleting role assignment: $($roleAssignment.name) for role definition: $($roleDefinition.name) in management group: $managementGroup"
58+
az role assignment delete --ids $roleAssignment.id
59+
} -ThrottleLimit 10
60+
61+
foreach ( $subscription in $using:subscriptions ) {
62+
$subscriptionRoleAssignments = az role assignment list --role $roleDefinition.name --subscription $subscription | ConvertFrom-Json
63+
$subscriptionRoleAssignments | ForEach-Object -Parallel {
64+
$roleDefinition = $using:roleDefinition
65+
$subscription = $using:subscription
66+
$roleAssignment = $_
67+
Write-Host "Deleting role assignment: $($roleAssignment.name) for role definition: $($roleDefinition.name) in subscription: $subscription"
68+
az role assignment delete --ids $roleAssignment.id
69+
} -ThrottleLimit 10
70+
}
71+
if($roleDefinition.isCustom -eq $true) {
72+
Write-Host "Deleting custom role definition: $($roleDefinition.name) in management group: $managementGroup"
73+
az role definition delete --name $roleDefinition.name --management-group $managementGroup
74+
}
75+
} -ThrottleLimit 10
4376
} -ThrottleLimit 10
4477

4578
$subscriptions | ForEach-Object -Parallel {

alz/azuredevops/variables.tf

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -785,20 +785,11 @@ variable "custom_role_definitions_bicep" {
785785
description = "This is a custom role created by the Azure Landing Zones Accelerator for running Bicep What If for the Management Group hierarchy and its associated governance resources such as policy, RBAC etc... You must use the `--validation-level providerNoRbac` (Az CLI 2.75.0 or later) or `-ValidationLevel providerNoRbac` (Az PowerShell 13.4.0 or later (Az.Resources 7.10.0 or later)) flag when running Bicep What If with this role."
786786
permissions = {
787787
actions = [
788-
"Microsoft.Management/managementGroups/read",
789-
"Microsoft.Management/managementGroups/subscriptions/read",
790-
"Microsoft.Management/managementGroups/settings/read",
791-
"Microsoft.Authorization/*/read",
792-
"Microsoft.Authorization/policyDefinitions/write",
793-
"Microsoft.Authorization/policySetDefinitions/write",
794-
"Microsoft.Authorization/roleDefinitions/write",
795-
"Microsoft.Authorization/policyAssignments/write",
796-
"Microsoft.Insights/diagnosticSettings/write",
797-
"Microsoft.Insights/diagnosticSettings/read",
788+
"*/read",
798789
"Microsoft.Resources/deployments/whatIf/action",
799-
"Microsoft.Resources/deployments/write",
800-
"Microsoft.Resources/deploymentStacks/read",
801-
"Microsoft.Resources/deploymentStacks/validate/action"
790+
"Microsoft.Resources/deployments/validate/action",
791+
"Microsoft.Resources/subscriptions/operationResults/read",
792+
"Microsoft.Management/operationResults/*/read"
802793
]
803794
not_actions = []
804795
}

0 commit comments

Comments
 (0)