Skip to content

feat(ec2): CreateFleet with seedable partial fulfillment; wire four CFN resource types (#387, #388, #389) - #390

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/ec2-createfleet-cfn-wiring-docs
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/ec2-createfleet-cfn-wiring-docs

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Jul 30, 2026 •

Copy link
Copy Markdown
Owner

Sprint covering #387, #388, and #389.

#387 — EC2 CreateFleet

Adds CreateFleet, DescribeFleets, DeleteFleets.

Instances launch through the same runInstances path as a direct launch, so they are visible to DescribeInstances with subnet/security-group validation, placement-group checks, and launch-time tag propagation intact.

LaunchTemplateConfigs[] × Overrides[] flatten into ordered capacity pools (sorted by Priority under a prioritized allocation strategy) and are fulfilled round-robin, so fleetInstanceSet carries one item per pool, each with a list of instance IDs — the shape the issue flags as the classic caller bug. An instant fleet returns instances and errors synchronously; request/maintain return only the fleet ID, matching AWS.

Partial fulfillment is seedable — the valuable part:

curl -X POST localhost:4566/v1/ec2/fleet-shortfall \
  -d '{"launchTemplate":"lt-0abc123","fulfill":8,
       "errorCode":"InsufficientInstanceCapacity","lifecycle":"spot"}'

A fleet that asks for 12 and receives 8 still returns a fleet ID and echoes the request in TotalTargetCapacity, never the result — which is exactly why callers get it wrong, and it is rare and hard to trigger against real AWS. The shortfall is spread across pools, so errorSet reports one item per short pool, and DescribeFleets reports the truth in fulfilledCapacity. Seeds are keyed by launch-template ID/name or \"*\", following the established pattern (ssm_control.go).

#388 — four CFN types fell to the generic stub

The handlers existed; the wiring didn't, so a stack deployed "successfully" while the resource was never created.

Type Now dispatches Ref
AWS::EC2::LaunchTemplate CreateLaunchTemplate real lt-… ID, usable by CreateFleet
AWS::IAM::InstanceProfile CreateInstanceProfile + AddRoleToInstanceProfile per Roles entry profile name
AWS::EC2::SecurityGroupIngress AuthorizeSecurityGroupIngress group ID
AWS::EC2::SecurityGroupEgress AuthorizeSecurityGroupEgress group ID

AWS::EC2::SecurityGroup now also authorizes its inline SecurityGroupIngress/SecurityGroupEgress rules. Previously neither spelling produced rules, so DescribeSecurityGroups reported an empty group however the template was written — the case the issue calls sharpest.

That needed a type change the issue didn't anticipate: EC2IPPermission had no way to express a rule whose source is another security group, and a self-referencing rule has no CIDR at all. Added UserIDGroupPairs, parsing of IpPermissions.N.Groups.M.GroupId, and groups>item rendering. While in the parser: it now reads every IpPermissions.N entry and all of each entry's IpRanges.M (it previously read only the first of each), and revoke matches on source as well as protocol/ports, so revoking a CIDR rule no longer removes a source-group rule on the same port.

AWS::EC2::Instance passes through IamInstanceProfile, KeyName, and SecurityGroupIds — the profile reference is only resolvable now that the profile is real.

The generic-stub warning reports service_plugin_loaded, the issue's suggested cheap improvement; it previously read as "substrate doesn't model this", misleading when only the wiring is missing.

AWS::EC2::NetworkInterface is left stubbed — it needs a CreateNetworkInterface handler first, which the issue notes belongs in its own issue.

#389 — doc drift

emulator/doc.go claimed 39 plugins and 23 S3 operations; the registry has 63 and s3_plugin.go 53. The counts #364 made generated had drifted here, so doc.go now points at the generated docs/services.md rather than repeating a number that can drift. CLAUDE.md's key-files table pointed at four paths that moved to emulator/ in the #310 reorg. (The stale next-release pin flagged in the same issue was already removed while cutting v0.81.0, so this PR no longer claims it.)

Verification

All wire shapes checked against the AWS API reference per CLAUDE.md, which caught two things worth noting:

23 new fleet subtests + 7 new CFN tests, covering full/partial/zero fulfillment, pool prioritization, spot lifecycle, tag propagation, error cases, instant-fleet visibility rules, delete with and without TerminateInstances, self-referencing and mutually-referencing security groups, and launch-template → CreateFleet composition.

make test (race), test/e2e, go vet, golangci-lint run ./... (0 issues), and make docs-reference-check all green.

Closes #387
Closes #388
Closes #389

@scttfrdmn scttfrdmn added this to the v0.77.0 milestone Jul 30, 2026
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

…FN types (#387, #388, #389)

EC2 Fleet (#387)
----------------
Add CreateFleet, DescribeFleets, and DeleteFleets. Instances launch through
the same runInstances path as a direct launch, so they are visible to
DescribeInstances with subnet/security-group validation, placement groups, and
launch-time tag propagation intact.

LaunchTemplateConfigs[] x Overrides[] flatten into ordered capacity pools
(sorted by Priority under a prioritized allocation strategy) and are fulfilled
round-robin, so fleetInstanceSet carries one item per pool each with a *list*
of instance IDs — the shape callers most often flatten incorrectly. An instant
fleet returns instances and errors synchronously; request/maintain fleets
return only the fleet ID, matching AWS.

Partial fulfillment is seedable via POST/DELETE /v1/ec2/fleet-shortfall, keyed
by launch-template ID/name or "*". A fleet that asks for 12 and receives 8
still returns a fleet ID and echoes the *request* in TotalTargetCapacity, so
this is where callers most often go wrong — and it is rare and hard to trigger
against real AWS. Seeding makes it instant and reproducible; the shortfall is
reported per pool in errorSet with a configurable code and lifecycle.

CFN wiring (#388)
-----------------
Four resource types had working API handlers but fell through to
deployGenericStub, so a stack deployed "successfully" while the resource was
never created:

- AWS::EC2::LaunchTemplate — Ref is the real lt-… ID, usable by CreateFleet
- AWS::IAM::InstanceProfile — creates the profile and attaches each Roles entry
- AWS::EC2::SecurityGroupIngress / ::SecurityGroupEgress — standalone rules,
  resolving Source/DestinationSecurityGroupId through Ref/GetAtt

AWS::EC2::SecurityGroup now also authorizes its inline SecurityGroupIngress/
Egress rules, which were parsed but never applied — so previously *neither*
spelling produced rules, and DescribeSecurityGroups reported an empty group
regardless of how the template was written.

This needed a type change: EC2IPPermission had no way to express a rule whose
source is another security group (a self-referencing rule has no CIDR at all).
Added UserIDGroupPairs, parsing of IpPermissions.N.Groups.M.GroupId, and
groups>item rendering in DescribeSecurityGroups. While there, the rule parser
now reads every IpPermissions.N entry and all of each entry's IpRanges.M rather
than only the first of each, and revoke matches on source as well as ports.

AWS::EC2::Instance passes through IamInstanceProfile, KeyName, and
SecurityGroupIds — the profile reference is only resolvable now that
AWS::IAM::InstanceProfile creates a real profile.

The generic-stub warning reports whether the type's service plugin is loaded;
it previously read as "substrate doesn't model this", misleading when the
actions exist and only the wiring is missing.

AWS::EC2::NetworkInterface is left stubbed — it needs a CreateNetworkInterface
handler first, which #388 notes belongs in its own issue.

Docs (#389)
-----------
emulator/doc.go claimed 39 plugins and 23 S3 operations; the registry has 63
and s3_plugin.go 53. The counts that #364 made generated had drifted here, so
doc.go now points at the generated docs/services.md rather than repeating a
number that can drift. CLAUDE.md's key-files table pointed at four paths that
moved to emulator/ in the #310 reorg and pinned a now-stale next version.

All wire shapes were verified against the AWS API reference: the XML elements
are fleetId/fleetInstanceSet/errorSet (not the boto3-facing names), and source
security groups use IpPermissions.N.Groups.M.GroupId.

Closes #387
Closes #388
Closes #389
@scttfrdmn
scttfrdmn force-pushed the feat/ec2-createfleet-cfn-wiring-docs branch from f165d64 to 789404e Compare August 1, 2026 07:08
@scttfrdmn

Copy link
Copy Markdown
Owner Author

Rebased onto main at v0.81.0 (was based on 03228a9, five releases back, and had gone CONFLICTING). Four conflicts, all in files v0.80.0/v0.81.0 also touched:

  • emulator/server.go — additive on both sides; kept all three control-plane route pairs (Lambda invoke-error, SQS consistency, EC2 fleet-shortfall).
  • docs/services.md — both sides added EC2 ops-table rows and a new section. Kept all rows and both sections. The security-group rows conflicted directly: main had added [Explicit resource IDs] links to DescribeSecurityGroups/DeleteSecurityGroup (EC2: describe_* by explicit ID returns empty list instead of Invalid*ID.NotFound #391) while this branch added source-SG notes and the two Revoke* rows. Both claims are true, so the resolution carries both — I verified the source-SG note against parseSGPermission in this branch rather than trusting the prose.
  • CLAUDE.md — both sides removed the stale next minor release is v0.68.0 pin. Kept main's version, which also states the rule (derive from the latest tag) so it cannot go stale again. This branch's key-files path fixes are untouched.
  • CHANGELOG.md — this branch's entries were written under ## [Unreleased] when v0.77.0 was pending; v0.81.0 has since shipped, so they now sit under a fresh ## [Unreleased] above the released sections.

One entry corrected. The #389 Fixed entry claimed the stale next-release pin as this PR's fix, but #432 removed it while cutting v0.81.0. Reworded to claim only the key-files path fixes and note the pin was already handled — otherwise the changelog would credit a fix that landed elsewhere.

Verification on the rebased commit: gofmt, go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test (race), cd test/e2e && go test ./..., make docs-reference-check, make docs-versions — all clean. Confirmed the two feature sets coexist rather than one having clobbered the other: the Fleet/CFN tests and the v0.80.0/v0.81.0 tests (SQS consistency, QueueDoesNotExist, RunInstances ImageId, multipart Content-Encoding) all pass together, and the diff is the same 3,021 insertions as before the rebase.

Not reviewed for correctness here — this was a rebase to make the PR mergeable again. Its three issues (#387, #388, #389) are on the v0.77.0 milestone, which is still open.

@scttfrdmn
scttfrdmn merged commit 1db1f5d into main Aug 1, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the feat/ec2-createfleet-cfn-wiring-docs branch August 1, 2026 07:12
@scttfrdmn scttfrdmn mentioned this pull request Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant