Repository navigation
feat(organizations): make account vending asynchronous (#578) - #607
Merged
Merged
Conversation
CreateAccount answered SUCCEEDED inline with an AccountId, which let a consumer with no poll loop pass its tests. AWS documents the operation as "an asynchronous request that Amazon Web Services performs in the background", and the poll loop is the part that has to survive being interrupted: the car- request ID is the only handle a resumed run has on an account that may or may not exist yet. CreateAccount now returns IN_PROGRESS with a persisted request ID and no AccountId, and DescribeCreateAccountStatus / ListCreateAccountStatus resolve it. MoveAccount is added, so an account can leave the root it lands in. The status resolves on first observation rather than after an interval of the simulated clock. A waiter therefore converges in one poll with no dependence on wall-clock or simulated time, and the terminal state never moves afterwards — a status that re-resolved would make a waiter comparing successive polls loop forever. Clock-driven transitions are #514, still open; picking a duration here would front-run that design. The terminal outcome is decided at request time and recorded apart from the request, so the account record and the status can never disagree. Deciding it at read time would let a seed cleared between the two produce a SUCCEEDED status naming an account that was never written. A request headed for FAILED writes no account at all: a FAILED request that left an account in ListAccounts is a state real AWS cannot produce, and it is the one most likely to make a consumer's cleanup path look correct while it deletes nothing. The seeded failure keeps the asymmetry that makes it worth having — CreateAccount still answers 200 with IN_PROGRESS, and only the status reports FAILED. A caller that checks the HTTP status and moves on never learns the account was not created. Refusals wired, each from the operation's declared errors list in the model: - CreateAccountStatusNotFoundException for an unknown request ID, so a resumed run holding a stale ID learns the request is gone rather than polling forever. - DuplicateAccountException when the destination is already the account's parent. This settles #578's point 5: a governance script re-run fails loudly and distinguishably instead of silently succeeding, which is the re-runnability property the issue is about. The destination is checked before the source so the re-run gets that answer rather than "your source OU does not exist". - SourceParentNotFoundException for a stale SourceParentId, which is why the parameter exists at all. - DestinationParentNotFoundException for an unknown destination. - InvalidInputException/MOVING_ACCOUNT_BETWEEN_DIFFERENT_ROOTS for an OU under another root, read from the root suffix an OU ID embeds. Refused as a cross-root move rather than a missing container, because the two send a caller to different places. - ConstraintViolationException/ACCOUNT_NUMBER_LIMIT_EXCEEDED on the 11th account, counting the management account. - InvalidInputException/INVALID_LIST_MEMBER for a States filter outside the CreateAccountState enum: a filter matching nothing reads exactly like "the organization vended nothing". One assertion outside this lane changed, in organizations_plugin_test.go: CreateAccount reports IN_PROGRESS, so the test now polls for the AccountId. That is the consumer-visible break. Part of #578.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 C of the v0.97.0 Organizations work: asynchronous account vending.
Part of #578— covers points 1, 2, 3 and 5 of the issue's nine, plus point 8 for the operations added here.What changed
CreateAccountansweredSUCCEEDEDinline with anAccountId. AWS documents the operation as "an asynchronous request that Amazon Web Services performs in the background", and a synchronous fake lets a consumer with no poll loop pass its tests — the poll loop being the part that has to survive an interruption, since thecar-request ID is the only handle a resumed run has on an account that may or may not exist yet.Operations:
CreateAccount(now asynchronous),DescribeCreateAccountStatus,ListCreateAccountStatus,MoveAccount. Every input/output member name, error code, enum and pattern was checked againstorganizations/2016-11-28/service-2.json; the request ID matches the model'sCreateAccountRequestIdpattern^car-[a-z0-9]{8,32}$.Design decisions worth reviewing
Resolution on first observation, not on the clock (point 1). The status resolves when it is first read, so a waiter converges in one poll with no dependence on wall-clock or simulated time, and the terminal state never moves afterwards — a status that re-resolved (a moving
CompletedTimestamp, a flip back toIN_PROGRESS) would make a waiter comparing successive polls loop forever. Clock-driven transitions are #514, still open; picking a duration here would front-run that design. TheOrganizationsPlugindoc comment already recorded this and remains accurate.The outcome is decided at request time, recorded apart from the request. A new
car_pending:record holds the terminal outcome the request is committed to. Deciding it at read time instead would let a seed cleared betweenCreateAccountand the first poll produce aSUCCEEDEDstatus naming an account that was never written, or aFAILEDstatus for an account sitting inListAccounts— states real AWS cannot reach. Keeping it out of the request record also means the storedCreateAccountStatusis always a shape AWS could return, which matters because substrate's state is meant to be inspectable at any point in history.A seeded failure writes no account (asked for explicitly in the lane brief). It should not, and does not. A
FAILEDrequest that left an account inListAccountsis a state real AWS cannot produce, and it is the one most likely to make a consumer's cleanup path look correct while it deletes nothing.CreateAccountstill returns 200 for a seeded failure (point 3). That asymmetry is the whole point of the seed: a caller that checks the HTTP status and moves on never learns the account was not created. Asserted directly.New accounts land in the root (point 2).
CreateAccounttakes no parent, soMoveAccountis the only way into an OU, and the account is inListAccountsimmediately — before any poll — as AWS reports it. A tool that assumes otherwise leaves accounts outside the OU where the policies are attached.Refusals wired, each from the operation's declared
errorslistCreateAccountRequestIdCreateAccountStatusNotFoundExceptionDuplicateAccountExceptionSourceParentIdis not the actual parentSourceParentNotFoundExceptionDestinationParentNotFoundExceptionInvalidInputException/MOVING_ACCOUNT_BETWEEN_DIFFERENT_ROOTSConstraintViolationException/ACCOUNT_NUMBER_LIMIT_EXCEEDEDStatesfilter outside the enumInvalidInputException/INVALID_LIST_MEMBERInvalidInputException/INVALID_PATTERNInvalidInputException/INPUT_REQUIREDTwo orderings are deliberate and commented:
Consumer-visible break
CreateAccountreportsState: "IN_PROGRESS"and carries noAccountId. A caller must pollDescribeCreateAccountStatuswith the returnedId. One assertion outside this lane changed for it —emulator/organizations_plugin_test.gonow polls for the account ID instead of reading it off the create response. That is the single line the lane brief flagged.Deliberately left out
CloseAccount. It did not fall out for free. AWS documents it as its own asynchronous journey observed throughDescribeAccount(ACTIVE→PENDING_CLOSURE→SUSPENDED), with its own refusals (AccountAlreadyClosedException,ConstraintViolationException/CANNOT_CLOSE_MANAGEMENT_ACCOUNT,CLOSE_ACCOUNT_QUOTA_EXCEEDED) and a 30-day quota. That is a second resolution mechanism on a different observation surface, not a few lines on this one.EMAIL_ALREADY_EXISTShalf of point 7). Reachable through the seed, not inferred from stored accounts. Inferring it would change the outcome of an existing fixture rather than add a path a test opts into — the foundation'sTestOrganizations_ListAccountsPaginatesvends three accounts sharing one email, and inferring uniqueness silently failed it. Left asTODO(#578)inpendingCreateOutcome; worth a follow-up decision, since making it automatic is a behaviour change for any existing fixture that reuses an address.RoleName/IamUserAccessToBillingare accepted and recorded nowhere. No Organizations API observation exposes either, so modeling them would be modeling the inside of the new account rather than the API surface.GovCloudAccountIdonCreateAccountStatus, since GovCloud vending is not modeled.Nothing contradicted the brief
The model agreed with the lane brief on every point checked: the
car-pattern, the three-valueCreateAccountStateenum,ListCreateAccountStatus'sStatesfilter, and all sixMoveAccountrefusals.orgMaxAccounts = 10and the 10-per-target / 10,240-byte SCP figures from the milestone comment are what the foundation already ships.Files
emulator/organizations_account.go— the lane's operations.emulator/organizations_account_test.go,emulator/organizations_account_export_test.go— new.emulator/organizations_plugin_test.go— the one-line assertion above.No shared file was otherwise touched:
HandleRequest,organizations_state.go,organizations_types.goandorganizations_export_test.goare unchanged. Two helpers live in this lane's file and could be hoisted later if another lane needs them:isOrgParentIDandorgOUNamesRoot.CHANGELOG.mdis untouched (PR 6 owns it).Verification
gofmt,go build ./...,go vet ./...,golangci-lint run ./emulator/(0 issues),go test ./emulator/ -run TestOrganizations, andmake test(race detector, whole repo) all clean. Per-function coverage of the new code is 89–100%, including the store-failure and corrupt-record boundaries in the style oforganizations_faults_test.go.