Skip to content

feat(ec2): key instance-type offerings by AZ ID (#893) - #897

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/ec2-offerings-availability-zone-id
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/ec2-offerings-availability-zone-id

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

DescribeInstanceTypeOfferings now answers LocationType=availability-zone-id, and the
unmodelled-LocationType refusal narrows to outpost alone.

Closes #893.

The recorded decision this reverses, and why the reversal is honest

The refusal was deliberate, not an oversight, and ec2UnmodelledLocationTypeError carried its
reason:

Substrate reports AZ IDs from DescribeAvailabilityZones but does not key offerings by them …
Refusing is the honest answer: treating either as availability-zone would return zone names
under a locationType saying they are IDs or ARNs, which a caller matching the two would
silently mis-read.

That argument holds exactly as written. So this PR does not relax it — it makes the first clause
false. Offerings are now keyed by AZ ID, and the second clause never applies because the response
carries real IDs rather than names mislabelled as IDs. The doc comment changed in the same
commit as the behaviour
, so nothing is left describing a refusal that no longer happens; a stale
rationale is the defect class this project spends releases removing.

outpost stays refused for the half of that reasoning nothing changed: its location is an Outpost
ARN, substrate seeds no Outpost, and there is no ARN it could report. The refusal message now
offers availability-zone-id among the remedies.

What AWS publishes

Verified against the API reference (both pages returned real content; nothing here is from
recollection):

  • API_DescribeInstanceTypeOfferings
    — LocationType Valid Values: region | availability-zone | availability-zone-id | outpost,
    and per-value: "availability-zone-id - The AZ ID. When you specify a location filter, it must
    be an AZ ID for the current Region", "outpost - The Outpost ARN. When you specify a location
    filter, it must be an Outpost ARN for the current Region".
  • API_InstanceTypeOffering
    — location is "The identifier for the location. This depends on the location type"; locationType
    Valid Values are the same four.

So the per-item locationType echoing availability-zone-id while location carries the ID is
the shape AWS documents, and that mismatch is what the issue was about.

Implementation

  • A fifth switch arm in describeInstanceTypeOfferings collecting ZoneID from
    ec2SeededZones(reqCtx.Region) — the single producer of a zone's name and ID, and what
    DescribeAvailabilityZones renders from. Not a reimplementation of azRegionAbbrev, so
    us-east-1a ↔ use1-az1 cannot drift between the two operations.
  • The availability-zone arm was switched onto the same producer (it enumerated
    ec2SeededAZSuffixes directly). Behaviour-identical today, and deliberate: one producer means a
    zone the seed later reports differently — an unavailable zone, a fourth zone — cannot leave the
    two arms disagreeing about which locations exist. Recorded in the handler comment rather than
    left to the diff.
  • ec2UnmodelledLocationTypeError narrowed to outpost, doc comment rewritten to the remaining
    reason and to record that EC2: DescribeInstanceTypeOfferings should model LocationType=availability-zone-id #893 reversed the other half.
  • The location filter needed no change, and this was verified rather than assumed — it
    compares against whatever the locations slice holds, so use1-az1 selects and us-east-1a
    selects nothing. Both directions are asserted.

The caveat a consumer needs

Substrate maps zone a to -az1 in every account, because a deterministic emulator cannot hold a
per-account secret, whereas AWS "independently map[s] Availability Zones to codes for each AWS
account". A consumer whose invariant is that AZ names are per-account randomised is correct against
AWS and will find substrate more forgiving. Read the ID out of DescribeAvailabilityZones; do not
hardcode use1-az1
— a test asserting the literal pairing passes here and asserts nothing about a
real account.

The tests are written to that rule: the new subtest builds a name→ID map from
DescribeAvailabilityZones and asserts the offerings' location against it, with no AZ-ID literal
anywhere. docs/services.md says the same thing at the point of use.

Two adjacent gaps, recorded and deliberately not touched

  • MaxResults and NextToken are unimplemented on this operation, although the handler's own
    doc comment lists them among the reference's parameters — so a paginating caller gets the whole
    set on every call with no nextToken. AWS specifies MaxResults as min 5 / max 1000 and a
    nextToken response element.
  • availability-zone-id is accepted-but-inert as a filter name on five other EC2 describes
    (emulator/ec2_filters.go, e.g. ec2SpotPriceFilterSpec's accepted list and the comment above
    it). The same ec2SeededZones pairing now makes those implementable, which is a strictly larger
    follow-up.

Verification

Run from the repo root, all green:

$ gofmt -l . && go build ./... && go vet ./...
gofmt-ok
build-ok
vet-ok

$ golangci-lint run ./...
0 issues.

$ make test          # redirected to a file; exit 0, zero FAIL lines
ok  github.com/scttfrdmn/substrate/emulator                  18.243s
ok  github.com/scttfrdmn/substrate/cmd/substrate              1.510s
ok  github.com/scttfrdmn/substrate/cmd/gen-authz-reference    1.495s
ok  github.com/scttfrdmn/substrate/cmd/gen-service-reference  1.933s

$ make docs-reference docs-reference-check docs-versions authz-reference-check
docs/services.md already up to date (67 plugins)
(all four targets clean)

TestEC2_DescribeInstanceTypeOfferings_LocationType — 7 subtests, all pass, including the two new
ones. npm --prefix docs run build was skipped: docs/node_modules is git-ignored and absent in a
fresh worktree, so it exits 127; CI covers the docs build.

One test changed rather than being added: the availability-zone-id/outpost refusal loop is now
outpost only. That test was passing on the old refusal, and its inversion is the reversal this
PR records — not a relaxed assertion.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

DescribeInstanceTypeOfferings now answers LocationType=availability-zone-id,
and the unmodelled-LocationType refusal narrows to outpost alone.

This reverses a recorded decision by making its premise false rather than by
relaxing it: ec2UnmodelledLocationTypeError gave the reason as substrate
"reports AZ IDs from DescribeAvailabilityZones but does not key offerings by
them", so offerings now key by AZ ID, taken from ec2SeededZones -- the single
producer of a zone's name and ID and what DescribeAvailabilityZones renders
from. The availability-zone arm reads the same producer, so the two forms of a
zone cannot drift. The doc comment moves with the behaviour in the same commit.

outpost stays refused for the untouched half of the original reasoning: its
location is an Outpost ARN and substrate seeds no Outpost.

Closes #893.
@scttfrdmn
scttfrdmn force-pushed the feat/ec2-offerings-availability-zone-id branch from bc8a54f to cd1c8a5 Compare September 15, 2026 22:15
@scttfrdmn
scttfrdmn merged commit d4142ec into main Sep 15, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/ec2-offerings-availability-zone-id branch September 15, 2026 22:26
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: DescribeInstanceTypeOfferings should model LocationType=availability-zone-id

1 participant