Skip to content

fix(ec2): a launch-declared data volume is preserved on termination (#675) - #678

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/675-data-volume-delete-on-termination
Aug 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/675-data-volume-delete-on-termination

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #675.

The conflict

Two current AWS pages disagree about DeleteOnTermination's default for a volume a launch creates:

  • block-device-mapping-concepts states the default is "true for the root volume and false for attached volumes".
  • preserving-volumes-on-termination carries a console-vs-CLI table listing a launch-created data volume as Delete when the launch came through the CLI.

#666 followed the second page and applied true to every launch-created volume, root and data alike. The code comment argued it well — "its termination table splits on how the volume was attached, not on what it is … and substrate has no console" — but presented the answer as simply AWS's documented behavior, with no note that another current page says the opposite.

Why the split wins

The API reference itself documents no default for EbsBlockDevice.DeleteOnTermination, and its only pointer on the subject is a link that no longer resolves to the content it cites. Both guide pages agree the real launch default comes from the AMI's own block device mapping — which substrate's AMIs do not carry. So the value is substrate's choice either way, and given a genuine ambiguity the non-destructive side is the one a test emulator should take: a volume wrongly preserved is visible and correctable, while one wrongly deleted is gone and the caller learns of it by its absence rather than by an error. A consumer reading the page that describes the mapping shape they are writing would otherwise find substrate wrong rather than opinionated.

What changed

  • ec2VolumeFromMapping defaults DeleteOnTermination to ec2IsRootDevice(device) rather than unconditional true. It keys off the resolved device name, so a mapping naming no device — which lands on /dev/sda1 — is treated as the root it became rather than as a data volume. An explicit value still wins.
  • AttachVolume's false is untouched and unaffected; both pages agree about a volume attached after launch, and its comment needed no root-device special case.
  • Three comments asserted the old rationale and all three now name the conflict: ec2_block_devices.go's ec2LaunchVolumesFor, EC2VolumeAttachment.DeleteOnTermination's field doc, and docs/services.md. The docs paragraph names both pages and states which wins and why, per the house provenance rule.

Fail-before proof

The contested default had no HTTP-tier coverage at all — every existing case either names a root device or sets the value explicitly. TestEC2_BlockDeviceMapping_DataVolumeDefaultPreserves was written first and run against main:

--- FAIL: TestEC2_BlockDeviceMapping_DataVolumeDefaultPreserves (0.00s)
    ec2_block_devices_http_test.go:261: Should be false
        Messages: a data volume with no explicit value is preserved (#675)
    ec2_block_devices_http_test.go:275: "[]" should have 1 item(s), but has 0
        Messages: the root is deleted and the data volume is not

The second failure is the one that matters: the volume was not merely mislabelled, it was destroyed.

Tests

  • Added TestEC2_BlockDeviceMapping_DataVolumeDefaultPreserves (HTTP) — root and data volume in one launch, neither naming the value, asserting the two differ and that termination honors the difference. The rendered flag and what termination does have to agree.
  • Added TestJourney_EC2LaunchDataVolumeSurvivesTermination (SDK) — the tier the change is consumer-visible at.
  • Inverted three TestEC2LaunchVolumes rows that pinned true for a data volume, and rewrote the case comment that argued for it. (The plan for this release recorded the default as untested; it was in fact pinned in three unit rows, which is where the fail-before evidence for the unit tier came from.)
  • Reaffirmed with a #675 note the two assertions the issue names — journey_ec2_block_devices_test.go and ec2_block_devices_http_test.go's repro — both of which are on a root device and so keep true.

Verification

gofmt, go build, go vet, golangci-lint run clean; make test (race) green; go test -C test/e2e ./... green; go run ./cmd/gen-service-reference -check and scripts/check-doc-versions.sh clean.

Compatibility

A data volume that a launch created and TerminateInstances deleted in v0.103.0/v0.104.0 now survives as available with no attachment, and DescribeVolumes reports deleteOnTermination=false on its attachment where it previously reported true. A mapping naming DeleteOnTermination explicitly is unaffected, as is every root-device mapping and every volume attached after launch.

…675)

Two current AWS pages disagree about DeleteOnTermination's default for a volume
a launch creates. block-device-mapping-concepts gives the split — true for the
root, false for attached volumes — while preserving-volumes-on-termination's
console-vs-CLI table lists a launch-created data volume as Delete. #666 followed
the second and applied true to everything, and both the code comment and the
docs presented that as simply AWS's documented behavior.

The API reference documents no default at all, and both guide pages agree the
real one comes from the AMI's own mapping, which substrate's AMIs do not carry.
So the value is substrate's choice either way, and the non-destructive side of a
genuine ambiguity wins: a volume wrongly preserved is correctable, one wrongly
deleted is gone.

The root still defaults to true, keyed off the resolved device name so a mapping
naming no device is treated as the root it becomes. AttachVolume is unchanged.
@scttfrdmn scttfrdmn added this to the v0.105.0 milestone Aug 20, 2026
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 4dc798b into main Aug 20, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/675-data-volume-delete-on-termination branch August 20, 2026 21: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: two AWS pages disagree on DeleteOnTermination's launch default for a data volume, and substrate does not record which it follows

1 participant