You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: alzlib.go
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -20,8 +20,9 @@ import (
20
20
)
21
21
22
22
const (
23
-
defaultParallelism=10// default number of parallel requests to make to Azure APIs
24
-
defaultOverwrite=false
23
+
defaultParallelism=10// default number of parallel requests to make to Azure APIs
24
+
defaultOverwrite=false
25
+
defaultUniqueRoleDefinitions=true// default to unique role definitions per management group
25
26
)
26
27
27
28
// AlzLib is the structure that gets built from the the library files
@@ -48,8 +49,9 @@ type azureClients struct {
48
49
49
50
// AlzLibOptions are options for the AlzLib.
50
51
typeAlzLibOptionsstruct {
51
-
AllowOverwritebool// AllowOverwrite allows overwriting of existing policy assignments when processing additional libraries with AlzLib.Init().
52
-
Parallelismint// Parallelism is the number of parallel requests to make to Azure APIs when getting policy definitions and policy set definitions.
52
+
AllowOverwritebool// AllowOverwrite allows overwriting of existing policy assignments when processing additional libraries with AlzLib.Init().
53
+
Parallelismint// Parallelism is the number of parallel requests to make to Azure APIs when getting policy definitions and policy set definitions.
54
+
UniqueRoleDefinitionsbool// UniqueRoleDefinitions indicates whether to update the role definitions to be unique per management group. If this is not set, you may end up with conflicting role definition names.
53
55
}
54
56
55
57
// NewAlzLib returns a new instance of the alzlib library, optionally using the supplied directory
Description: to.Ptr("Contributor role granted for application/operations team at resource group level"),
501
+
},
502
+
},
503
+
},
504
+
},
505
+
}
506
+
507
+
h.mgs["mgRoot"] =mgRoot
508
+
h.mgs["mg1"] =mg1
509
+
510
+
mgRoot.children=mapset.NewThreadUnsafeSet(mg1)
511
+
require.NoError(t, mgRoot.update(true))
512
+
require.NoError(t, mg1.update(true))
513
+
514
+
// Check that the role definitions are unique
515
+
assert.NotEqual(t, *mgRoot.roleDefinitions["rdRoot01"].Name, *mg1.roleDefinitions["rdMg101"].Name, "Role definitions should not have the same ID")
516
+
assert.NotEqual(t, *mgRoot.roleDefinitions["rdRoot01"].Properties.RoleName, *mg1.roleDefinitions["rdMg101"].Properties.RoleName, "Role definitions should not have the same ID")
517
+
assert.NotEqual(t, *mgRoot.roleDefinitions["rdRoot01"].ID, "/providers/Microsoft.Management/managementGroups/mgRoot/providers/Microsoft.Authorization/roleDefinitions/8a60c97f-9cb6-536b-b5db-9c997ee1de03", "Role definitions should not have the same ID after update")
518
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].ID, fmt.Sprintf("/providers/Microsoft.Management/managementGroups/mgRoot/providers/Microsoft.Authorization/roleDefinitions/%s", *mgRoot.roleDefinitions["rdRoot01"].Name), "Role definitions should have the same ID after update")
519
+
assert.NotEqual(t, *mgRoot.roleDefinitions["rdRoot01"].Name, "8a60c97f-9cb6-536b-b5db-9c997ee1de03", "Role definitions should have the same Name after update")
520
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].Properties.RoleName, fmt.Sprintf("[ALZ] Application-Owners (%s)", mgRoot.id), "Role definitions should have the same RoleName after update")
Description: to.Ptr("Contributor role granted for application/operations team at resource group level"),
563
+
},
564
+
},
565
+
},
566
+
},
567
+
}
568
+
569
+
h.mgs["mgRoot"] =mgRoot
570
+
h.mgs["mg1"] =mg1
571
+
572
+
mgRoot.children=mapset.NewThreadUnsafeSet(mg1)
573
+
require.NoError(t, mgRoot.update(false))
574
+
require.NoError(t, mg1.update(false))
575
+
576
+
// Check that the role definitions are still not unique after update
577
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].Name, *mg1.roleDefinitions["rdMg101"].Name, "Role definitions should not have the same ID after update")
578
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].Properties.RoleName, *mg1.roleDefinitions["rdMg101"].Properties.RoleName, "Role definitions should not have the same ID after update")
579
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].ID, "/providers/Microsoft.Management/managementGroups/mgRoot/providers/Microsoft.Authorization/roleDefinitions/8a60c97f-9cb6-536b-b5db-9c997ee1de03", "Role definitions should have the same ID after update")
580
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].Name, "8a60c97f-9cb6-536b-b5db-9c997ee1de03", "Role definitions should have the same Name after update")
581
+
assert.Equal(t, *mgRoot.roleDefinitions["rdRoot01"].Properties.RoleName, "[ALZ] Application-Owners", "Role definitions should have the same RoleName after update")
0 commit comments