Skip to content

feat(organizations): implement the organizational-unit tree (#578) - #608

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/organizations-ou-tree-578
Aug 9, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/organizations-ou-tree-578

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Lane A of the v0.97.0 Organizations work: the OU tree. Builds on the foundation from #606.

What this covers of #578

  • The "OU tree" cluster — all five operations the issue lists (CreateOrganizationalUnit, DescribeOrganizationalUnit, ListOrganizationalUnitsForParent, ListParents, ListAccountsForParent), plus UpdateOrganizationalUnit, DeleteOrganizationalUnit, and ListChildren. The last three are not in the issue's list but the tree is not testable without them: without Delete a test cannot tear a tree down, and without ListChildren a caller cannot walk downward the way ListParents walks up.
  • Point 4 (nothing is idempotent, and each refuses differently) for the OU row of that table: DuplicateOrganizationalUnitException, and the delete's second call refusing with OrganizationalUnitNotFoundException rather than succeeding silently.
  • Point 7 (reachable quotas) for the OU depth limit of 5 and the OU count limit of 2,000.
  • Point 8 (pagination on every List*) for all four listings here, each through the foundation's orgPaginate, each rejecting a stale NextToken rather than silently restarting.

Fidelity

Every input/output member name, error list, and enum was read out of the botocore model (organizations/2016-11-28/service-2.json), not from recall. Confirmations worth recording:

  • OrganizationalUnit has exactly Id, Arn, Name — no Path. A test asserts the response carries no other member, so nothing can come to depend on a field AWS would not send.
  • The OU ID pattern is ^ou-[0-9a-z]{4,32}-[a-z0-9]{8,32}$, whose middle segment is the root's suffix. A nested OU therefore still names the root, not its parent OU; there is a test for that specifically, since a caller parsing the ID to find its root would otherwise read the wrong thing from the second level down.
  • ListChildren requires ChildType (enum ACCOUNT | ORGANIZATIONAL_UNIT), so the operation never mixes kinds. An unrecognized value is refused rather than treated as "everything" — a caller with a typo would otherwise get a superset and draw type conclusions from a filter that never applied.
  • ListParents' ChildId pattern admits only a 12-digit account ID or an OU ID; a root is explicitly not a child, and is refused with InvalidInputException.
  • MaxResults caps at 20 in the model, which the foundation's orgPaginate already clamps to.
  • Nothing in the model contradicted the lane brief. Its ID formats, ARN shape, refusal codes, and the orgMaxOUDepth/orgMaxOUsPerOrg values all check out against it.

The refusals, and why each one matters

Refusal Code
Sixth nesting level ConstraintViolationException / OU_DEPTH_LIMIT_EXCEEDED
2001st OU ConstraintViolationException / OU_NUMBER_LIMIT_EXCEEDED
More than 50 inline tags ConstraintViolationException / MAX_TAG_LIMIT_EXCEEDED
Duplicate name under the same parent DuplicateOrganizationalUnitException
Well-formed parent ID naming nothing ParentNotFoundException
Unknown OU on describe/update/delete OrganizationalUnitNotFoundException
Unknown child on ListParents ChildNotFoundException
Deleting a populated OU OrganizationalUnitNotEmptyException
ID of the wrong shape, missing required member, bad enum, repeated tag key, stale NextToken InvalidInputException (reason in the message)

All at HTTP 400, per the foundation — the model declares no 404 for any Organizations exception.

Two distinctions are deliberate rather than incidental:

  • A malformed ID is InvalidInputException, not a not-found code. Answering "not found" for an ID that could never have named anything sends the caller looking for a missing entity instead of telling it the ID it built is wrong.
  • Duplicate-name checking is scoped to the parent, and excludes the OU itself. The common layout gives every business unit an identically named Sandbox, so an organization-wide check would refuse a legal tree; and renaming an OU to the name it already has must succeed, or a converging governance script could never reissue its own rename.

DeleteOrganizationalUnit unwinds every index that names the OU — record, organization OU index, both directions of the placement, policy attachments, tags. A leftover entry is invisible until something reads it, and then it reads as an entity present in one listing and absent from another, which is a state no sequence of API calls can produce.

Tests

emulator/organizations_ou_test.go, 95.4% statement coverage of the lines added (the remainder is duplicated error-propagation branches). The two that carry the most weight:

  1. The depth boundary. Builds a chain to exactly orgMaxOUDepth and asserts the next level refuses with OU_DEPTH_LIMIT_EXCEEDED. A legal 5-deep tree and an illegal 6th level are indistinguishable on a nominal run, so this is the only thing that catches an off-by-one in either direction. Verified by mutation: changing the comparison to parentDepth > orgMaxOUDepth fails it.
  2. The Organizations: ListRoots mints a new random root ID on every call, so the root has no identity #577/Organizations: OUs, policies, and account placement are unimplemented, so the whole account-vending surface is unreachable #578 join. Walks ListParents upward from the member account and asserts it terminates at the same root ID ListRoots reports. Before the root was persisted that walk could never match; it is the property the rest of the release rests on.

Plus: duplicate-name scoping proven both ways (same name under two parents succeeds, same parent refuses); delete refusing for a child OU and for a contained account, then succeeding once emptied and disappearing from both ListOrganizationalUnitsForParent and DescribeOrganizationalUnit; rename preserving ID, ARN, children, and attachments; FullAWSAccess auto-attached at creation while SCPs are enabled and not attached under CONSOLIDATED_BILLING; every listing paginated to exhaustion and rejecting a stale token; and store-failure/corrupt-record boundaries in the style of organizations_faults_test.go — a store blip is a 500 an SDK retries, never a 400 not-found that would send a caller down a create-again path.

Deliberately left out

  • MoveAccount is the account lane's. Tests that need an account inside an OU place it through the foundation's placeChild rather than inventing a handler for it.
  • TagResource / ListTagsForResource are the tagging lane's. CreateOrganizationalUnit stores its own inline Tags because the model puts them in its input shape and documents that an invalid one fails the whole request, but nothing here reads them back over the API.
  • No seed endpoint. Every alternate outcome in this cluster is reachable by arranging the tree, so a seed would add a knob with no path it uniquely unlocks.
  • AccessDeniedException / ConcurrentModificationException / ServiceException / TooManyRequestsException / AWSOrganizationsNotInUseException are in the model's error lists but not wired: the first is authz's, the next three have no deterministic trigger, and the last cannot occur while the organization is auto-created on first observation.

New private helpers in this file, for later hoisting

Per the lane split, these live in organizations_ou.go and are flagged rather than added to the shared state file: requireOrgParent, requireOU, childrenOfKind, ouSiblingNameTaken, forgetOU, orgDeleteKey, isOrgAccountID, orgValidateOUTags, and the constant orgMaxOUNameChars. orgDeleteKey and isOrgAccountID are the two most likely to be wanted by another lane — deletion is the one thing the foundation's storage helpers do not cover, and the account-ID shape test is needed anywhere a ChildId is validated.

CHANGELOG.md untouched, per the split (PR 6 owns it).

Part of #578.

Fills in the OU cluster of the Organizations plugin: CreateOrganizationalUnit,
DescribeOrganizationalUnit, UpdateOrganizationalUnit, DeleteOrganizationalUnit,
ListOrganizationalUnitsForParent, ListParents, ListChildren, and
ListAccountsForParent. Every shape, error code, and enum was checked against the
botocore model rather than recall, and each refusal below is in its operation's
declared error list.

The refusals are the point, not the CRUD. Each one exists because the state it
prevents is one a caller cannot detect afterwards:

- OU_DEPTH_LIMIT_EXCEEDED on a sixth level. A legal 5-deep tree and an illegal
  6th look identical on a nominal run, so an off-by-one here is invisible until
  a real deploy rejects a tree substrate accepted. The test builds the chain to
  the limit and asserts the next level refuses; mutating the comparison to
  `parentDepth > orgMaxOUDepth` fails it.
- DuplicateOrganizationalUnitException scoped to the parent, not the
  organization. The common layout gives every business unit an identically named
  "Sandbox", so an organization-wide check would refuse a legal tree; a rename
  to the name an OU already has is likewise not a duplicate, or a converging
  script could never reissue it.
- OrganizationalUnitNotEmptyException on a populated OU. Deleting one would
  orphan its accounts somewhere no listing reaches.
- ParentNotFoundException for a well-formed parent ID naming nothing, kept
  distinct from InvalidInputException for an ID of the wrong shape: a malformed
  ID answered as not-found sends the caller looking for an entity that could
  never have existed.
- ChildNotFoundException on ListParents, and InvalidInputException for a root as
  the ChildId, which the model's ChildId pattern excludes.
- OU_NUMBER_LIMIT_EXCEEDED at orgMaxOUsPerOrg, and MAX_TAG_LIMIT_EXCEEDED /
  DUPLICATE_TAG_KEY on the inline tags, all validated before anything is
  written — the operation documents that an invalid tag leaves no OU behind, and
  a partial create would make the caller's retry hit a duplicate refusal for an
  OU it does not believe it created.

DeleteOrganizationalUnit unwinds every index that names the OU: the record, the
organization's OU index, both directions of the placement, the policy
attachments, and the tags. A leftover entry is invisible until something reads
it, and then it reads as an entity present in one listing and absent from
another — a state no sequence of API calls can produce, so nothing downstream
handles it.

Two properties get dedicated tests because nothing else would catch them: the
depth boundary above, and the #577/#578 join — walking ListParents upward from a
member account terminates at the same root ID ListRoots reports. Before the root
was persisted that walk could never match, and it is the property the rest of
the release is built on.

Part of #578.
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.73743% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/organizations_ou.go 92.73% 13 Missing and 13 partials ⚠️

📢 Thoughts on this report? Let us know!

…test

Lane C made CreateAccount asynchronous, so the call no longer carries an
AccountId. The listing test now vends through the shared orgVendAccount
helper, which polls DescribeCreateAccountStatus once.
@scttfrdmn
scttfrdmn merged commit 30d8cbf into main Aug 9, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/organizations-ou-tree-578 branch August 9, 2026 17:07
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.

1 participant