Skip to content

feat(ec2): a snapshot has a real size, and a nonexistent one is refused (#689) - #701

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/689-createsnapshot
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/689-createsnapshot

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #689.

EC2Snapshot.VolumeSize was the literal 8, and substrate had no CreateSnapshot at all
(InvalidAction / HTTP 400) — so the only snapshots it held were the ones CreateImage mints for
an AMI's root device, all of them 8 GiB whatever the instance's root volume was. Every
size-dependent rule was therefore a comparison against a constant, which is precisely why v0.105.0
deferred the block-device-mapping rule that a size must not be smaller than its snapshot's, and why
#685's volume-size filter had a single value to select on.

Four changes, one theme: the constant 8 becomes a real value, and a snapshot ID gets checked.

CreateSnapshot

VolumeId is required and resolved against state through the existing ec2VolumeIDKind machinery:
absent is MissingParameter, a syntactically invalid ID is InvalidVolumeID.Malformed, one that
names nothing is InvalidVolume.NotFound — so a snapshot cannot exist for a volume that does not.
volumeSize and encrypted come from the source volume rather than the request, which is what AWS
documents ("the size of the volume, in GiB"; "snapshots that are taken from encrypted volumes are
automatically encrypted"). Description and TagSpecification.N are read, the tags through the
same walk and the same two rules as every other tag-on-create, checked before anything is
written.

The response element is status, not state — verified against the CreateSnapshot reference,
whose documented values are pending | completed | error | recoverable | recovering. It is
completed at once, not the pending AWS's own sample shows: substrate advances no snapshot
asynchronously, so a caller's waiter succeeds on its first poll rather than depending on wall-clock
time. A seedable pending → completed progression is the shape that would let a test exercise the
waiting path, and is a follow-up rather than nondeterministic behaviour. Location and OutpostArn
are not read — both are documented as supported only for a Local Zone or an Outpost, neither of
which substrate models.

The two literal 8s

createImage wrote volumeSize: 8, and describeImages rendered a second, independent literal
8 for the same snapshot in its own ebs member (the one this issue does not mention). Two
constants that agreed only for as long as neither knew a real size. Both now read the volume
record — ec2InstanceRootVolume scans for the volume attached at a device passing
ec2IsRootDevice — so an AMI made from a 40 GiB root volume reports 40 GiB through
DescribeSnapshots and through DescribeImages. The snapshot also records the source volume's
ID, which finally gives DescribeSnapshots' volume-id filter something to select on for the only
snapshots substrate could previously produce. An AMI whose snapshot was since deleted falls back to
the 8 GiB default rather than reporting 0.

The snapshot checks on a block device mapping

A mapping naming a snapshot was accepted unconditionally and materialized an 8 GiB volume, so a
launch real EC2 rejects succeeded here and left state a consumer then asserted against — the same
class of defect #671 closed for the six mapping rules it added.

  • Malformed ID → InvalidSnapshotID.Malformed; names nothing → InvalidSnapshot.NotFound.
    Both come from ec2SnapshotIDKind, which already produced the exact code, message and status.
  • Ebs.VolumeSize below the snapshot's → InvalidBlockDeviceMapping, the refusal v0.105.0
    deferred. AWS documents the rule verbatim on EbsBlockDevice.VolumeSize: "You can specify a
    volume size that is equal to or larger than the snapshot size."

The two carry different codes on purpose: a snapshot substrate cannot find is a mistake about the
ID — which is what naming a snapshot from a previous run looks like — while a size below it is a
mistake about the mapping. A refusal leaves no state behind, because the check sits where #671 put
the validator: after the launch-template merge, before the default-VPC branch.

ec2CheckBlockDeviceMappings was pure and snapshot existence needs state, so it takes a
resolveSnapshot func(string) (EC2Snapshot, bool) rather than a *StateManager — the validator
stays unit-testable with a two-line closure, and #693's collecting variant can wrap the same
signature. Rule order is load-bearing and the doc comment states both halves: the snapshot
checks run after the size-or-snapshot requirement (a mapping naming neither has no snapshot to
look up) and before the Throughput/Iops rules, which return nil early on an absent VolumeType
and would otherwise skip the snapshot check entirely.

And the mirror of the same defect

A mapping with a present SnapshotId and absent VolumeSize yielded ec2DefaultVolumeSizeGiB
= 8, because ec2VolumeFromMapping took nothing from the snapshot. EC2BlockDeviceMapping's own
field doc already stated the correct rule — the doc was ahead of the code — and AWS states it on the
same member it states the refusal on: "If you specify a snapshot, the default is the snapshot size."
ec2ResolveSnapshotSizes fills it in a pre-resolution step before ec2CreateLaunchVolumes, which
keeps both pure functions pure and fixes DescribeVolumes' reported size for free. It keys off
VolumeSizeRaw == "", which is what makes an absent value distinguishable from an unparseable one.

createVolume had the identical gap independently — a restore from a 30 GiB snapshot produced an
8 GiB volume there too, and one naming a snapshot no account holds succeeded outright — and now
applies both rules through the same comparison.

CreateTags reaches a snapshot

A snap- ID had no arm in ec2TaggableResource, so CreateTags on a snapshot answered
<return>true</return> having written nothing — the same silent no-op #670 fixed for vol-, and
immediately relevant now that CreateSnapshot's TagSpecification gives a caller a snapshot of
their own. Until this change DescribeTags (#688, this release) could report a snapshot's tags that
CreateTags had no way to write. The image/lt/fleet arms each need their own ARN-format
verification and stay in #695.

Provenance

status and its five values, VolumeId's Required: Yes, the size-inheritance default and the
equal-or-larger refusal are all from the CreateSnapshot and EbsBlockDevice references, fetched
this session — both "If you specify a snapshot, the default is the snapshot size" and "You can
specify a volume size that is equal to or larger than the snapshot size" appear verbatim on
CreateVolume.Size and EbsBlockDevice.VolumeSize, so the same rule is applied through both
doors. Neither operation's Errors section lists anything beyond the common errors, so the specific
codes come from EC2's errors-overview page (InvalidSnapshot.NotFound,
InvalidSnapshotID.Malformed, InvalidVolume.NotFound, InvalidVolumeID.Malformed are all
documented there) rather than from the per-operation pages. completed at once is substrate's,
not AWS's sample; so is which code applies to which of the two mapping mistakes.

Fail-before

emulator/ec2_snapshots_test.go and test/e2e/journey_ec2_snapshots_test.go run against main
(85a01b4), all seven tests and thirteen subtests failing:

--- FAIL: TestEC2_CreateSnapshot_ReportsTheSourceVolume (0.00s)
    status = 400, want 200; body = <Response><Errors><Error><Code>InvalidAction</Code>
    <Message>EC2Plugin: unknown action CreateSnapshot</Message></Error></Errors>...
--- FAIL: TestEC2_BlockDeviceMapping_RefusesAnUnknownSnapshot (0.00s)
    Error: Not equal: expected: "InvalidSnapshot.NotFound"  actual: ""
    Error: Should be empty, but was [{vol-9db4f82f… 8 gp2 …} {vol-ec5e5c7b… 8 gp2 us-east-1a
      in-use false snap-0123456789abcdef0 …}]
    Messages: a refused launch materializes no volume
    Error: Not equal: expected: "InvalidSnapshotID.Malformed"  actual: ""
--- FAIL: TestEC2_CreateImage_SnapshotSizeIsTheRootVolume (0.00s)
    Error: Not equal: expected: 40  actual: 8
    Messages: the AMI's snapshot is the root volume's size
    Error: Not equal: expected: 40  actual: 8
    Messages: DescribeImages reads the snapshot's size rather than rendering its own constant
--- FAIL: TestEC2_CreateVolume_InheritsTheSnapshotSize
--- FAIL: TestEC2_BlockDeviceMapping_InheritsTheSnapshotSize
--- FAIL: TestEC2_CreateTags_TagsASnapshot
--- FAIL: TestEC2_CreateSnapshot_RefusesAVolumeItCannotFind/absent

The nonexistent-snapshot case is the one worth reading twice: not only was the launch accepted, it
materialized a volume carrying snap-0123456789abcdef0 — a snapshot no account holds — at the
8 GiB default.

And at the SDK tier:

--- FAIL: TestJourney_EC2SnapshotRestore (0.01s)
    CreateSnapshot: operation error EC2: CreateSnapshot, https response error StatusCode: 400,
    api error InvalidAction: EC2Plugin: unknown action CreateSnapshot
--- FAIL: TestJourney_EC2SnapshotRefusals (0.00s)
    (same)

Two tests rewritten rather than extended

  • TestEC2_BlockDeviceMapping_ValidIsAccepted/a_snapshot_with_no_size asserted that a mapping
    naming snap-0123456789abcdef0 is accepted. Under the existence check it is refused, so the
    row now seeds a real 30 GiB snapshot — and a sibling row asserts a size equal to the snapshot's
    is accepted, since the rule is equal-or-larger.
  • TestEC2_DescribeTags_ScanIsWiderThanCreateTags asserted "CreateTags has no snap- arm yet".
    That is now false; it asserts both the CreateTags-written and TagSpecification-written tags
    come back.

Two assertions I expected to break still pass, and now for the right reason: the int64(8) in
ec2_plugin_test.go and the volume-size "8" filter row. The seeded instances genuinely have 8 GiB
root volumes, so 8 went from a constant to a real value. Both got a comment saying so, plus a
require.NotEmpty on the newly-recorded VolumeID and a real volume-id selection row, so nothing
passes by coinciding with a constant.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test
(race, all packages), make docs-reference-check, make docs-versions, and
go vet -C test/e2e ./... && go test -C test/e2e ./... all clean. Coverage unchanged in shape: the
new file arrives with the seven tests above plus the journey.

…ed (#689)

Substrate had no CreateSnapshot, and every snapshot it did hold — the ones
CreateImage mints for an AMI's root device — recorded volumeSize as the
literal 8. Two independent literals, in fact: createImage wrote one and
describeImages rendered a second for the same snapshot. So every
size-dependent rule was a comparison against a constant, which is why
v0.105.0 deferred the rule that a mapping's size must not be smaller than
its snapshot's.

CreateSnapshot reads VolumeId (required, checked against state),
Description and TagSpecification.N, and takes volumeSize and encrypted
from the source volume. status is completed at once: substrate advances no
snapshot asynchronously, so a waiter succeeds on its first poll rather
than depending on wall-clock time.

With a real size to compare against, a block device mapping naming a
snapshot that does not exist is refused (InvalidSnapshotID.Malformed or
InvalidSnapshot.NotFound), a size below the snapshot's is refused
(InvalidBlockDeviceMapping), and a mapping naming a snapshot and no size
inherits the snapshot's size instead of the 8 GiB default. CreateVolume
had the identical gap independently and now applies both rules through
the same comparison. CreateTags gains the snap- arm it was missing, so
tagging a snapshot stops silently no-opping.
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.52866% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_snapshots.go 73.40% 13 Missing and 12 partials ⚠️
emulator/ec2_plugin.go 87.87% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ae23038 into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/689-createsnapshot branch August 21, 2026 06:46
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.

ec2: EC2Snapshot.VolumeSize is a constant, no CreateSnapshot exists, and a named snapshot is never checked

1 participant