Skip to content

feat(organizations): make account vending asynchronous (#578) - #607

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/organizations-account-vending-578
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/organizations-account-vending-578

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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

CreateAccount answered SUCCEEDED inline with an AccountId. 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 the car- 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 against organizations/2016-11-28/service-2.json; the request ID matches the model's CreateAccountRequestId pattern ^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 to IN_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. The OrganizationsPlugin doc 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 between CreateAccount and the first poll produce a SUCCEEDED status naming an account that was never written, or a FAILED status for an account sitting in ListAccounts — states real AWS cannot reach. Keeping it out of the request record also means the stored CreateAccountStatus is 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 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.

CreateAccount still 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). CreateAccount takes no parent, so MoveAccount is the only way into an OU, and the account is in ListAccounts immediately — 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 errors list

Case Code
Unknown CreateAccountRequestId CreateAccountStatusNotFoundException
Destination is already the account's parent DuplicateAccountException
SourceParentId is not the actual parent SourceParentNotFoundException
Unknown destination DestinationParentNotFoundException
OU under another root InvalidInputException / MOVING_ACCOUNT_BETWEEN_DIFFERENT_ROOTS
11th account, management account counted ConstraintViolationException / ACCOUNT_NUMBER_LIMIT_EXCEEDED
States filter outside the enum InvalidInputException / INVALID_LIST_MEMBER
Malformed parent ID InvalidInputException / INVALID_PATTERN
Missing required member InvalidInputException / INPUT_REQUIRED

Two orderings are deliberate and commented:

  • Destination before source. A governance script re-run replays the move it recorded (source root, destination OU). The useful answer is "that account is already present in the specified destination", not "your source OU does not exist", which is what validating the source first would say. This settles point 5, which was uncertain whether the move should be a no-op: it is a refusal, and a re-run fails distinguishably instead of silently succeeding.
  • Cross-root before not-found. An OU ID embeds its root's suffix, so an OU naming another root is a cross-root move on its face. The two refusals send a caller to different places — "this move is not possible" versus "create the OU first".

Consumer-visible break

CreateAccount reports State: "IN_PROGRESS" and carries no AccountId. A caller must poll DescribeCreateAccountStatus with the returned Id. One assertion outside this lane changed for it — emulator/organizations_plugin_test.go now 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 through DescribeAccount (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.
  • Organization-wide email uniqueness (the EMAIL_ALREADY_EXISTS half 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's TestOrganizations_ListAccountsPaginates vends three accounts sharing one email, and inferring uniqueness silently failed it. Left as TODO(#578) in pendingCreateOutcome; worth a follow-up decision, since making it automatic is a behaviour change for any existing fixture that reuses an address.
  • RoleName / IamUserAccessToBilling are 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.
  • GovCloudAccountId on CreateAccountStatus, 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-value CreateAccountState enum, ListCreateAccountStatus's States filter, and all six MoveAccount refusals. orgMaxAccounts = 10 and 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.go and organizations_export_test.go are unchanged. Two helpers live in this lane's file and could be hoisted later if another lane needs them: isOrgParentID and orgOUNamesRoot.

CHANGELOG.md is untouched (PR 6 owns it).

Verification

gofmt, go build ./..., go vet ./..., golangci-lint run ./emulator/ (0 issues), go test ./emulator/ -run TestOrganizations, and make 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 of organizations_faults_test.go.

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

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.60104% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/organizations_account.go 88.60% 11 Missing and 11 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit d01dbbe into main Aug 9, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/organizations-account-vending-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