Skip to content

feat(ec2): an instance reports its own block devices (#669) - #679

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/669-instance-block-device-mapping
Aug 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/669-instance-block-device-mapping

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

DescribeInstances, RunInstances and DescribeInstanceAttribute now render a
blockDeviceMapping set for an instance.

#666 made a launch materialize its EBS volumes, but the only way to learn which volume sat
on which device was DescribeVolumes filtered on attachment.instance-id — a question real
EC2 answers from the instance. DescribeInstanceAttribute refused blockDeviceMapping
outright, which was right when there was nothing to render.

The set is derived from the volumes, not from the request

That is the design decision the whole change rests on, and it is what satisfies the
detached-later-stops-appearing criterion for free:

EC2Instance carries no block-device field, so the volumes are also the only available
source. The mapping from state to AWS's shape is one-to-one and total — deviceName ←
att.Device, volumeId ← vol.VolumeID, status ← att.State, attachTime ←
att.AttachTime, deleteOnTermination ← att.DeleteOnTermination — so nothing is
fabricated.

The volume list is read once per request and bucketed by instance ID.
describeInstances already does one List plus a Get per security group per instance, so
a per-instance List would compound into an instances × volumes scan.

Shape

InstanceBlockDeviceMapping is exactly deviceName + ebs. EbsInstanceBlockDevice has
eight members and no size; the four AWS's own sample shows are rendered, in its order.
The other four (associatedResource, ebsCardIndex, operator, volumeOwnerId) are
omitted rather than defaulted — substrate records nothing behind them, and a fabricated
volumeOwnerId is indistinguishable to a caller from a real one.

Because there is no size member, this does not close #666's gap: docs/services.md
still says DescribeVolumes is the only surface a launch-specified size is observable on,
and that sentence is deliberately kept true.

EbsInstanceBlockDevice.status uses the four-value AttachmentStatus enum, while
DescribeVolumes' volume-side status is a five-value enum that adds busy — so the two are
deliberately not rendered through one shared helper, and the type comment says why.

On DescribeInstanceAttribute the response needs both halves of the existing groupSet
pattern: a *ec2BlockDeviceMappingSetXML pointer field, so the element is absent from a
userData response (encoding/xml emits the parent of a foo>item path even when the
slice is empty), and an unconditional non-nil assignment in its own case, so an instance
with no EBS volumes renders present-but-empty. No <value> wrapper — it is one of the
InstanceAttribute members that is not an AttributeValue.

Two divergences from the issue's premises, corrected rather than implemented

The issue says RunInstances' response should render the set "since the reference shows it
there too". It does not.
The reference's only RunInstances sample response emits
<blockDeviceMapping />, empty, on a pending instance whose request declared no mappings
at all. Rendering it populated is a deliberate divergence, argued on substrate's own
grounds — the same ones ec2_plugin.go already records for networkInterfaceSet: substrate's
instances are running and their volumes exist by the time RunInstances answers. The code
comment and the release's ## Provenance say so rather than claiming AWS settles it.

The issue calls the two ec2InstanceItem structs duplicates; they had already drifted
again.
describeInstances' copy carried iamInstanceProfile and runInstancesResponse'
did not, they used different Go types for the state element, and their
placement/instanceState order was swapped. So RunInstances silently omitted the
instance profile DescribeInstances reported for the same instance — a live #444-class
defect, fixed as a side effect of the hoist and given its own ### Fixed CHANGELOG line
rather than landing quietly. ec2InstanceItem and its four sub-items are now package-level
with one builder, following the ec2GroupItem / ec2NetworkInterfaceItem precedents whose
comments record the original #444 bug.

Ordering

Sorted by device name, volume ID breaking a tie. DescribeInstances states outright that
its own order may vary, so no fidelity claim rests on this — but state-listing order is
not a promise substrate makes, and a deterministic emulator answering one request two ways
would break the guarantee the project exists for. No test asserts element order within an
item.

Fail-before proof

All eight new tests fail on the pre-fix tree. DescribeInstances and RunInstances return
zero mappings, and the attribute surface refuses:

InvalidParameterValue: Value (blockDeviceMapping) for parameter attribute is invalid. Unknown attribute.

Tests

Eight HTTP-tier tests in emulator/ec2_instance_blockdevices_test.go, reusing #666's
bdmRunInstances / bdmDescribeVolumes helpers: the three surfaces; that RunInstances and
DescribeInstances agree byte-for-byte on the set (the drift above); that the volume IDs
agree with what DescribeVolumes reports for the same instance; instance-store and
NoDevice; attach-then-detach tracking; per-instance bucketing on a two-count launch;
present-but-empty on the attribute surface after termination; and stable order across four
identical requests.

ec2AttributeSupported is an allow-list with a catch-all default: return false, so the
change is "the allow-list grew" and the "blockDeviceMapping" row in
TestEC2_InstanceAttribute_UnknownAttribute is deleted. Its doc comment now records that
the row left deliberately and that the remaining five still cover all four refusal classes —
listed-and-rejected-by-AWS, not-an-attribute, listed-and-unmodelled, and right-name-wrong-case.

Verification

gofmt -l clean, go build ./..., go vet ./..., golangci-lint run ./... (0 issues),
make test (race, all packages), go vet -C test/e2e ./... + go test -C test/e2e ./...,
gen-service-reference -check, scripts/check-doc-versions.sh, npm --prefix docs run build.

Docs

Two sites, not the one the issue names: the launch-time-storage "not modeled" paragraph
loses both blockDeviceMapping clauses and gains a new "An instance reports its own block
devices"
subsection, and the instance-attributes section's unmodelled-attributes list
drops the name while its table grows a fifth row. The two operation-table rows and the
DescribeInstanceAttribute row are updated too.

Closes #669

DescribeInstances, RunInstances and DescribeInstanceAttribute now render a
blockDeviceMapping set. The set is derived from the volume records rather than
from the mappings a launch recorded, so it tracks reality rather than intent: a
volume attached after launch appears, a detached one stops appearing, and an
instance store device never appears because it never became a volume.

Hoisting ec2InstanceItem to package level also fixes a live #444-class drift:
RunInstances omitted the iamInstanceProfile DescribeInstances reported for the
same instance.
@scttfrdmn
scttfrdmn merged commit 52ee67a into main Aug 20, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the feat/669-instance-block-device-mapping branch August 20, 2026 22:00
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.72973% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_instance_blockdevices.go 71.87% 5 Missing and 4 partials ⚠️
emulator/ec2_plugin.go 88.57% 2 Missing and 2 partials ⚠️
emulator/ec2_instanceattribute.go 71.42% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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