Repository navigation
fix: allow six levels of management groups in an architecture - #257
Merged
Qi Zhang (Zhangqi910) merged 1 commit intoNov 27, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #257 +/- ##
==========================================
+ Coverage 55.87% 55.92% +0.05%
==========================================
Files 56 56
Lines 5264 5270 +6
==========================================
+ Hits 2941 2947 +6
+ Misses 2003 2002 -1
- Partials 320 321 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Qi Zhang (Zhangqi910)
requested a review
from Akshay Rohilla (akshayrohilla)
November 27, 2026 14:40
Akshay Rohilla (akshayrohilla)
approved these changes
Nov 27, 2026
Qi Zhang (Zhangqi910)
deleted the
user/yingjie/fix-issue-4349-architecture-depth
branch
November 27, 2026 15:11
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An architecture with six levels of management groups fails to load with
architectureRecursion: recursion depth exceeded, although Azure supports six levels below the tenant root group (Azure/Azure-Landing-Zones#4349). This PR fixes an off-by-one inarchitectureRecursion: an architecture can now contain six levels, and the error for a deeper one names the management group that is too deep.Refs Azure/Azure-Landing-Zones#4349. Not "Fixes": Terraform users get the fix with the terraform-provider-alz release that upgrades to this version, and the issue will be closed then.
Root cause
architectureRecursionadds one level of management groups per call:depth > MaxRecursionDepth(5), before anything else.depth+1to look for their children.Step 3 always runs once more after the deepest level has been added. For six levels (depths 0-5), that call is at depth 6 and fails in step 1 before it finds that there are no children, so the effective limit was five levels.
Six levels was the intent:
level0-level6).management_groups_level_6;management_groups_level_5could never be used.Not a regression: the check dates from #116 (v0.14.0); #210 only moved the
5intoMaxRecursionDepth.Changes
alzlib.goarchitectureRecursionchecks the depth where a management group would be added (once its parent is found in the previous level), instead of on entry. The error names the management group, its level and the limit. The comment ofMaxRecursionDepthnow says that it is the maximum zero-based depth, i.e. six levels; its value (5) is unchanged.alzlib_test.goTestGenerateArchitecturesTbt: a new "management group hierarchy at maximum depth" case with six levels; the "too deep" case expects the new error; successful cases also check that every management group was added.The error for seven levels, before and after:
Behaviour notes
MaxRecursionDepthkeeps its value.Level()indeployment.Hierarchyand thelevelattribute of the provider'salz_architecturestay zero-based (0-5).Validation
go test ./...(incl. the read-only Azure integration tests),go vet ./...golangci-lintv2.11.4 with Go 1.25.2 (--new-from-rev)TestGenerateArchitecturesTbtandTestInitSimple,-count=20mainrecursion depth exceeded; "too deep" fails on the messagerequire.NoError, but fails the new "every management group was added" assertion:should have 6 item(s), but has 5main(5461147)main, all 9 guards pass on both; all 8 mutants of the fix are caught (limit one lower or higher, no limit, deepest level skipped silently, zero-based level or wrong limit in the message,MaxRecursionDepth = 6, the original entry check)mainand with this branch, comparing management groups, parents, levels, archetypes and thedeployment.Hierarchyplatform/alz,platform/ambaandtestdata/simple: byte-identical. Exactly six levels (16): fail onmain; with this PR every management group is built, the deepest at level 5. Seven to nine levels (40): rejected by both, and the new error always names a management group at level 7alzlibtool check library --offlinemain, passes with this PR; seven levels: fails with the new errorLive Azure, read-only (
terraform planonly, nothing applied), avm-ptn-alz 0.22.0. "Before" is terraform-provider-alz v0.22.1 as released or built againstmain; "This PR" is v0.22.1 built against this branch.Failed to initialize AlzLib...recursion depth exceededmanagement_groups_level_5, none inmanagement_groups_level_6recursion depth exceededmanagement group ...-level7 is at level 7, but an architecture can contain at most 6 levels of management groupsalz_architectureforplatform/alz@2026.11.0,platform/slz@2026.11.0,platform/amba@2026.10.0Open question
Should an architecture whose root is the tenant root group itself (
exists: true) be allowed seven levels? This PR keeps six: an architecture is usually placed below the tenant root group, where a seventh level always fails when it is applied, and rejecting it when the library loads is better than a partial apply. Allowing seven would only change the constant and the tests.Follow-ups (not in this PR)
parent_resource_id; management groups withexists: truecount). alzlib does not know how deep the parent management group is, so an architecture below a non-root parent can still exceed the Azure limit when it is applied.deployment.Hierarchy.ManagementGroupsAtLevelreturns every management group (return h.mgsinstead ofreturn res). Nothing in alzlib or terraform-provider-alz calls it; I'll open a separate issue.