Repository navigation
feat(organizations): implement the organizational-unit tree (#578) - #608
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 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.
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.
Lane A of the v0.97.0 Organizations work: the OU tree. Builds on the foundation from #606.
What this covers of #578
CreateOrganizationalUnit,DescribeOrganizationalUnit,ListOrganizationalUnitsForParent,ListParents,ListAccountsForParent), plusUpdateOrganizationalUnit,DeleteOrganizationalUnit, andListChildren. The last three are not in the issue's list but the tree is not testable without them: withoutDeletea test cannot tear a tree down, and withoutListChildrena caller cannot walk downward the wayListParentswalks up.DuplicateOrganizationalUnitException, and the delete's second call refusing withOrganizationalUnitNotFoundExceptionrather than succeeding silently.List*) for all four listings here, each through the foundation'sorgPaginate, each rejecting a staleNextTokenrather 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:OrganizationalUnithas exactlyId,Arn,Name— noPath. A test asserts the response carries no other member, so nothing can come to depend on a field AWS would not send.^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.ListChildrenrequiresChildType(enumACCOUNT|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'ChildIdpattern admits only a 12-digit account ID or an OU ID; a root is explicitly not a child, and is refused withInvalidInputException.MaxResultscaps at 20 in the model, which the foundation'sorgPaginatealready clamps to.orgMaxOUDepth/orgMaxOUsPerOrgvalues all check out against it.The refusals, and why each one matters
ConstraintViolationException/OU_DEPTH_LIMIT_EXCEEDEDConstraintViolationException/OU_NUMBER_LIMIT_EXCEEDEDConstraintViolationException/MAX_TAG_LIMIT_EXCEEDEDDuplicateOrganizationalUnitExceptionParentNotFoundExceptionOrganizationalUnitNotFoundExceptionListParentsChildNotFoundExceptionOrganizationalUnitNotEmptyExceptionNextTokenInvalidInputException(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:
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.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.DeleteOrganizationalUnitunwinds 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:orgMaxOUDepthand asserts the next level refuses withOU_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 toparentDepth > orgMaxOUDepthfails it.ListParentsupward from the member account and asserts it terminates at the same root IDListRootsreports. 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
ListOrganizationalUnitsForParentandDescribeOrganizationalUnit; rename preserving ID, ARN, children, and attachments;FullAWSAccessauto-attached at creation while SCPs are enabled and not attached underCONSOLIDATED_BILLING; every listing paginated to exhaustion and rejecting a stale token; and store-failure/corrupt-record boundaries in the style oforganizations_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
MoveAccountis the account lane's. Tests that need an account inside an OU place it through the foundation'splaceChildrather than inventing a handler for it.TagResource/ListTagsForResourceare the tagging lane's.CreateOrganizationalUnitstores its own inlineTagsbecause 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.AccessDeniedException/ConcurrentModificationException/ServiceException/TooManyRequestsException/AWSOrganizationsNotInUseExceptionare 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.goand are flagged rather than added to the shared state file:requireOrgParent,requireOU,childrenOfKind,ouSiblingNameTaken,forgetOU,orgDeleteKey,isOrgAccountID,orgValidateOUTags, and the constantorgMaxOUNameChars.orgDeleteKeyandisOrgAccountIDare 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 aChildIdis validated.CHANGELOG.mduntouched, per the split (PR 6 owns it).Part of #578.