Repository navigation
Description
What
#473 added disableApiTermination to DescribeInstanceAttribute and made
ModifyInstanceAttribute write it, so termination protection is now recorded at launch
(RunInstances' DisableApiTermination), modifiable, and readable back.
It is not acted on. TerminateInstances terminates a protected instance and
reports success.
Real EC2 refuses:
OperationNotPermitted: The instance 'i-0123456789abcdef0' may not be terminated.
Modify its 'disableApiTermination' instance attribute and try again.
Why it matters
This is the tracker's recurring shape: substrate returns success where real AWS
refuses, so a consumer's error branch is unreachable and their suite reports green
while verifying nothing.
It is worse than the usual instance of that, because the whole point of termination
protection is to be a guard rail. A test that asserts "my teardown script does not
destroy the protected instance" passes against substrate today and against a code
path that ignores protection entirely — the assertion cannot fail. Someone verifying
that guard rail before it protects real infrastructure gets no signal at all.
Scope
TerminateInstancesrefuses an instance withDisableAPITerminationset, with
OperationNotPermitted, HTTP 400.- Per-instance, not per-request.
TerminateInstancestakesInstanceId.N. Worth
checking against the reference whether a request naming one protected and one
unprotected instance terminates the unprotected one or refuses whole — the answer
determines whether this is a pre-flight check or a per-item outcome, and getting it
backwards is the same class of defect in the other direction. DeleteFleets(TerminateInstances=true)and theinstant-fleet teardown path reach
the same code, so decide and document what happens to a protected fleet instance.- The message above needs its provenance checked before shipping — it is from memory of
the console/CLI wording, not a verified capture. Per Error message text is substrate-shaped rather than AWS-shaped across ~650 AWSError literals #487, either find a capture or a
parity-tested reimplementation, or ship substrate's own text and say so in the
comment.
Acceptance criteria
-
TerminateInstanceson a protected instance returnsOperationNotPermitted, 400,
and the instance staysrunning. - Clearing protection via
ModifyInstanceAttribute(DisableApiTermination.Value=false)
then terminating succeeds — the sequence a consumer's teardown actually performs. - The mixed-request behaviour matches the reference, whichever way it goes, with the
citation in the code comment. - The fleet teardown path's behaviour is decided, tested, and documented in
docs/services.md. -
docs/services.md's instance-attributes section drops the "recorded and reported
but not acted on" caveat.
Noted as tracked separately in emulator/ec2_types.go's DisableAPITermination comment
and in docs/services.md, both added by #473.
Activity
fix(ec2): TerminateInstances honours termination protection (#489) (#504
scttfrdmn commentedon Aug 2, 2026
Fixed in
b502c5f(#504), shipping in v0.87.0. Your framing was right about the defect and about the risk, and the mixed-request answer is neither of your two guesses.Partial failure is Availability-Zone-scoped. You asked whether a mixed request refuses whole or terminates the unprotected instance, and noted that getting it backwards is the same defect in the other direction. There were three answers, not two. From
TerminateInstances:The reference then works a four-instance example. So substrate now groups the requested instances by AZ; any AZ containing a protected instance terminates none of its instances, other AZs proceed, and the request reports
OperationNotPermitted(400) naming the protected instance — after persisting the terminations in the unaffected zones. That ordering is the behaviour, not an implementation detail, and it is the natural thing to get wrong. The grouping is one testable function (ec2TerminationProtectionBlocked) rather than control flow inside the handler, and the AZ table in the test suite is modelled on the reference's own example. It fails under both of the behaviours you guessed at.Your existing observation that a single bad instance ID fails the whole request is also documented ("If you specify multiple instances and the request fails … none of the instances are terminated") and substrate already did that via
ec2RequireResource; the protection scan runs as a second pre-flight pass so no state is written for a doomed zone.Your provenance caution was warranted, and in both directions.
OperationNotPermittedturns out to have stronger backing than you expected — the EC2 client-error table names termination protection explicitly: "you might be trying to terminate an instance that has termination protection enabled." So the code is a doc citation. The message is not: you flagged your wording as from memory rather than a capture, nothing corroborates it, so substrate ships its own text interpolating the instance ID, labelled as substrate's in the comment perdocs/fidelity.md's policy. Your remembered wording is not dressed up as observed.The fleet path is now decided rather than inherited.
deleteFleetssynthesizes aTerminateInstancesrequest through the same handler, so protection applied for free — but "for free" is not the same as "correct," so it is asserted: a protected fleet instance survivesDeleteFleets --terminate-instancesexactly as it survives a direct terminate, an unprotected sibling in another zone does not, andDeleteFleetspropagates theOperationNotPermittedrather than folding it intounsuccessfulFleetDeletionSet. That last part is a real choice:DeleteFleetError's documented codes are exactlyfleetIdDoesNotExist,fleetIdMalformed,fleetNotInDeletableStateandunexpectedError, none of which covers termination protection — folding it in would mean answeringunexpectedErrorand losing the code the caller acts on.Both your acceptance criteria are covered, including the second one, which is the sequence a teardown actually performs:
ModifyInstanceAttribute(DisableApiTermination.Value=false)then terminate → succeeds. Protection set at launch viaRunInstances --disable-api-terminationis honoured too, not just protection set by modify. And terminating an already-terminated instance still succeeds, since the reference calls the operation idempotent and the new check must not break that.Your point about the test that cannot fail is the sharpest instance of this defect shape in the tracker's history, and worth restating for anyone reading later: a consumer asserting "my teardown does not destroy the protected instance" passed against a code path that ignored protection entirely, so the assertion could not fail. That is worse than a missing feature.
One divergence remains, deliberately out of scope here: substrate reported
48terminatedimmediately where real EC2 reports32shutting-downfirst. Widening this PR into a lifecycle change would have put your gate at risk. It turns out to be broader than terminate —pendingandstoppingare equally unobservable — and is filed as #514 with the three candidate designs.chore(release): v0.87.0 (#515)