mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* feat(organizations): add CloudFormation resource types Adds OrganizationsCfnProvisioner covering AWS::Organizations::Organization, OrganizationalUnit, Account, Policy and ResourcePolicy. Attribute names are taken from the registry schemas' readOnlyProperties so Fn::GetAtt resolves the keys AWS publishes. CloudFormation's delete path hands over a physical id and a region but no caller identity, and every Organizations mutation is management-account scoped. Rather than injecting a second collaborator into the provisioner, OrganizationsService gains findManagementAccountForResource, which recovers the owning account from the resource id — so the provisioner keeps to the one-injected-service convention the other provisioners follow. provision serves create and update: an OU is renamed in place rather than recreated (ParentId is create-only in the schema), a Policy's TargetIds are reconciled in both directions, and an Account is moved to its ParentIds entry after creation. The integration test asserts through stack Outputs backed by Fn::GetAtt: an unmapped attribute does not fail provisioning, it silently resolves to the literal "LogicalId.Attr", so asserting CREATE_COMPLETE would pass with every attribute unwired. * fix(organizations): converge CFN provisioning on partial failure and tag drops Set the physical id as soon as the create call succeeds in provisionAccount and provisionPolicy, before moveAccount and reconcileTargets respectively. Both can throw once the resource already exists — a ParentIds entry pointing at a missing OU raises DestinationParentNotFoundException, and attachPolicy can fail on a bad target — and without an id CloudFormation's rollback has nothing to call delete() with, leaving the account or policy a real member of the organization but unmanaged by the stack. Make putResourcePolicy replace its tag map rather than merge into it, so a key dropped from a template is removed on update instead of lingering. A resource policy is not a TagResource target, so resolveTagOwner rejects rp- ids and the provisioner cannot reach it through replaceTags the way the other types do; Put is the only call that can converge those tags. Supplying Tags states the full set, while omitting them leaves the existing ones untouched, matching how an absent Tags property behaves for every other Organizations type. * fix(organizations): mark created accounts and policies as rollback-owned CloudFormationService.rollbackCreatedResources deletes a CREATE_FAILED resource only when it carries both a physical id and the CfnRollback.ROLLBACK_OWNED_ATTR marker. The provisioner set the id but not the marker, so rollback walked straight past an account whose MoveAccount failed after CreateAccount had already made it a member of the organization. The account survived, the organization could not be deleted while it still contained one, and the stack reported ROLLBACK_FAILED instead of unwinding. Set the marker as soon as the create call returns, the way IamRoleCfnProvisioner does, so the create and the ownership record cannot drift apart. OrganizationsCfnRollbackIntegrationTest drives a real stack whose ParentIds names an OU that does not exist and asserts the account id reaches the stack events, that rollback emits DELETE_COMPLETE for it, and that neither the account nor the organization is left behind. * feat(organizations): map OU Path and Account State/Paths The published registry schemas declare three readOnly properties the provisioner did not map: OrganizationalUnit Path, and Account State and Paths. An unmapped key does not fail provisioning — CloudFormationTemplateEngine resolves it to the literal string "LogicalId.Attr" — so a template asking for Fn::GetAtt Dev.State silently got back "Dev.State". Path and Paths are the organization path, o-<org>/r-<root>[/ou-<ou>]*[/<id>]/, which needs a walk from the resource up to the root. OrganizationsService owns that hierarchy and already computes the chain for effective-policy merging, so it exposes it as organizationPath rather than the provisioner rebuilding it. The account path is read after the move: accounts are always created under the root, so reading it earlier would publish a path the account no longer lives at. State is the parameter AWS is retiring Status in favour of on 2026-09-09. Floci only ever puts an account in ACTIVE or PENDING_CLOSURE, both of which are also AccountState values, so the two agree; PENDING_ACTIVATION and CLOSED are phases the emulator does not model. Paths is list-typed in the schema, but an account has exactly one parent and so exactly one path, and the engine's Fn::Select splits a comma-delimited scalar back into a list, so the string-valued attribute map carries it without loss. Adding the Path lookup to provisionOrganizationalUnit opens the same window that stranded accounts before: a call that can throw once the OU is already a real member of the organization. Mark the OU stack-owned as soon as the create returns, matching the account and policy paths, so rollback can still delete it. * fix(organizations): Ref on Organization returns the management account id AWS documents Organization as the one Organizations type where bare Ref returns the management account id rather than the resource's own id; Fn::GetAtt Org.Id already returned the organization id correctly. Adds an OrgRef stack output/assertion covering the case, since the existing integration test only ever exercised Fn::GetAtt on Org.