Skip to content

Commit c874c80

Browse files
anwatherAnthony Watherston
andauthored
Add custom management groups to ALZ sync process (#1018)
Co-authored-by: Anthony Watherston <[email protected]>
1 parent d763520 commit c874c80

File tree

4 files changed

+115
-19
lines changed

4 files changed

+115
-19
lines changed
13.1 KB
Loading

Docs/integrating-with-alz-library.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,101 @@ Example to generate assignments with guardrails assignments included.
211211
# Sync the ALZ policies and assign to the "epac-dev" PAC environment.
212212
Sync-ALZPolicyFromLibrary -DefinitionsRootFolder .\Definitions -Type ALZ -PacEnvironmentSelector "epac-dev" -CreateGuardrailAssignments
213213
```
214+
215+
### Using a custom library for custom management group structures
216+
217+
Azure environments may not always be aligned with the default management group structure suggested by Azure Landing Zones. In this case it is required to maintain your own version of the Azure Landing Zone library repository and make changes in there to the default structure. This will increase the overall complexity in maintaining synchronisation as you will have to manage any updates to the forked repository.
218+
219+
In the example below it follows a typical customer customization where instead of having a corp/online management group structure it has been elected to use a non-production/production management group structure.
220+
221+
The updated management group structure would follow similar to below:-
222+
223+
```
224+
--Azure Landing Zones MG
225+
|_Non-Production MG
226+
|_ Production MG
227+
```
228+
229+
1. Create a fork of the [Azure Landing Zone Library](https://github.com/Azure/Azure-Landing-Zones-Library) and clone it locally. When later running the `New-ALZPolicyDefaultStructure` and `Sync-ALZPolicyFromLibrary` commands you will need to ensure the `-LibraryPath` parameter points to this cloned repo.
230+
2. For ALZ there are two files which need to be updated - firstly we need to add the new management group archetypes into the `\platform\alz\architecture_definitions\alz.alz_architecture_definition.json` file. In this example I will remove the `corp` and `online` entries from this file and replace them with a non-production and production key as below:-
231+
232+
```
233+
{
234+
"archetypes": [
235+
"non-production"
236+
],
237+
"display_name": "Non-Production",
238+
"exists": false,
239+
"id": "non-production",
240+
"parent_id": "landingzones"
241+
},
242+
{
243+
"archetypes": [
244+
"production"
245+
],
246+
"display_name": "Production",
247+
"exists": false,
248+
"id": "production",
249+
"parent_id": "landingzones"
250+
}
251+
```
252+
253+
3. Now that the new archetypes have been added there needs to be archetype defintion files created - which tie together which assignments are associated to these archetypes. For this example we will apply the same assignments as what would have been applied to the `corp` management group to the new management groups.
254+
4. In the forked repository in the folder `\platform\alz\archetype_definitions` we can copy the `corp.alz_archetype_definition.json` file twice and rename it to `non-production.alz_archetype_definition.json` and `production.alz_archetype_definition.json`. For each file update the `name` key in the file to match e.g.
255+
256+
```
257+
{
258+
"$schema": "https://raw.githubusercontent.com/Azure/Azure-Landing-Zones-Library/main/schemas/archetype_definition.json",
259+
"name": "production",
260+
"policy_assignments": [
261+
"Audit-PeDnsZones",
262+
"Deny-HybridNetworking",
263+
"Deny-Public-Endpoints",
264+
"Deny-Public-IP-On-NIC",
265+
"Deploy-Private-DNS-Zones"
266+
],
267+
"policy_definitions": [],
268+
"policy_set_definitions": [],
269+
"role_definitions": []
270+
}
271+
```
272+
273+
5. Since the `corp` and `online` archetypes no longer exist I can rename the archetype files for these with a `.bak` extension so the sync script does not include them.
274+
6. The new structure file can now be generated - for example:-
275+
276+
```
277+
New-ALZPolicyDefaultStructure -DefinitionsRootFolder .\Definitions\ -Type ALZ -LibraryPath ..\alz-library-fork\ -PacEnvironmentSelector epac-dev
278+
```
279+
280+
This file will contain the new management groups in the structure file as below:-
281+
282+
```
283+
"non-production": {
284+
"value": "/providers/Microsoft.Management/managementGroups/non-production",
285+
"management_group_function": "Non-Production"
286+
},
287+
"production": {
288+
"value": "/providers/Microsoft.Management/managementGroups/production",
289+
"management_group_function": "Production"
290+
}
291+
```
292+
293+
7. Run the sync command to import the policies and generate the assignments - for example:-
294+
295+
```
296+
Sync-ALZPolicyFromLibrary.ps1 -DefinitionsRootFolder .\Definitions\ -Type ALZ -LibraryPath ..\alz-library-fork\ -PacEnvironmentSelector epac-dev
297+
```
298+
299+
8. There are now two new folders in the `policyAssignments\ALZ` folder as below, and looking at the assigned scope for the assignments we can see they are going to be assigned to the correct management group.
300+
301+
![Assignment File Overview Diagram](Images/new-management-groups.png)
302+
303+
```
304+
"scope": {
305+
"epac-dev": [
306+
"/providers/Microsoft.Management/managementGroups/non-production"
307+
]
308+
}
309+
```
310+
311+
9. When maintaining parity with updates from the ALZ team including policy changes and new assignments it will be necessary to sync your forked repo and carefully check the incoming changes.

Scripts/CloudAdoptionFramework/New-ALZPolicyDefaultStructure.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ if ($Tag -eq "") {
4848

4949
if ($LibraryPath -eq "") {
5050
$LibraryPath = Join-Path -Path (Get-Location) -ChildPath "temp"
51+
git clone --config advice.detachedHead=false --depth 1 --branch $Tag https://github.com/Azure/Azure-Landing-Zones-Library.git $LibraryPath
5152
}
5253

53-
git clone --config advice.detachedHead=false --depth 1 --branch $Tag https://github.com/Azure/Azure-Landing-Zones-Library.git $LibraryPath
54-
5554
$jsonOutput = [ordered]@{
5655
managementGroupNameMappings = [ordered]@{}
5756
enforcementMode = "Default"
@@ -141,7 +140,7 @@ foreach ($parameter in $policyDefaults) {
141140
if ($Type -eq "AMBA") {
142141
$assignmentFileName = $assignmentFileName -replace ("-", "_")
143142
}
144-
$file = Get-ChildItem -Recurse -Path ".\temp" -Filter "$assignmentFileName" -File | Select-Object -First 1
143+
$file = Get-ChildItem -Recurse -Path $LibraryPath -Filter "$assignmentFileName" -File | Select-Object -First 1
145144
$jsonContent = Get-Content -Path $file.FullName -Raw | ConvertFrom-Json
146145
$tempDefaultParamValue = $jsonContent.properties.parameters.$parameterAssignmentName.value
147146

Scripts/CloudAdoptionFramework/Sync-ALZPolicyFromLibrary.ps1

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,27 @@ Param(
1818

1919
# Latest tag values
2020
if ($Tag -eq "") {
21-
switch ($Type) {
22-
'ALZ' {
23-
$Tag = "platform/alz/2025.02.0"
24-
}
25-
'FSI' {
26-
$Tag = "platform/fsi/2025.03.0"
27-
}
28-
'AMBA' {
29-
$Tag = "platform/amba/2025.05.0"
30-
}
31-
'SLZ' {
32-
$Tag = "platform/slz/2025.03.0"
33-
}
34-
}
21+
switch ($Type) {
22+
'ALZ' {
23+
$Tag = "platform/alz/2025.02.0"
24+
}
25+
'FSI' {
26+
$Tag = "platform/fsi/2025.03.0"
27+
}
28+
'AMBA' {
29+
$Tag = "platform/amba/2025.05.0"
30+
}
31+
'SLZ' {
32+
$Tag = "platform/slz/2025.03.0"
33+
}
34+
}
3535
}
3636

3737
if ($LibraryPath -eq "") {
3838
$LibraryPath = Join-Path -Path (Get-Location) -ChildPath "temp"
39+
git clone --config advice.detachedHead=false --depth 1 --branch $Tag https://github.com/Azure/Azure-Landing-Zones-Library.git $LibraryPath
3940
}
4041

41-
git clone --config advice.detachedHead=false --depth 1 --branch $Tag https://github.com/Azure/Azure-Landing-Zones-Library.git $LibraryPath
42-
4342
if ($DefinitionsRootFolder -eq "") {
4443
if ($null -eq $env:PAC_DEFINITIONS_FOLDER) {
4544
if ($ModuleRoot) {

0 commit comments

Comments
 (0)