Skip to content

feat(ec2): DescribeTags, the operation whose whole job is finding resources by tag (#688) - #700

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/688-describetags
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/688-describetags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #688.

DescribeTags — the EC2 operation whose whole job is finding resources by tag — reached the
dispatcher's default: arm and answered InvalidAction / HTTP 400, while four bundled
managed policies granted ec2:DescribeTags
: AmazonVPCFullAccess and
AmazonVPCReadOnlyAccess name it outright (emulator/iam_managed.go:785, :878), and
AmazonEC2FullAccess and AmazonEC2ReadOnlyAccess reach it through ec2:* and
ec2:Describe*. A policy permitted an operation nothing served.

Real EC2 offers three routes to a resource's tags: this operation, a tag:<key> filter on
each describe, and Resource Groups Tagging. Substrate served the third in full and the second
on five operations (#685/#686/#687, earlier in this milestone). This is the first.

What it does

New emulator/ec2_describetags.go plus one dispatch arm beside CreateTags/DeleteTags.

  • Response: AWS's TagDescription — resourceId, resourceType, key, value — under
    tagSet>item, plus nextToken,omitempty. Its own struct rather than ec2TagItem, which
    carries no resource. No omitempty on value: AWS's Example 1 renders <value/> for a
    tag whose value is empty, and an SDK tells a present-but-empty element from an absent one.
  • Filters — exactly five, all evaluated, none inert: key, resource-id,
    resource-type, value, tag:<key>. This is the only operation in the family with an
    empty accepted list.
  • No tag-key. Alone in the describe family, this operation documents none — its key
    filter already matches a key whatever its value. So tag-key is refused here while it
    is accepted on every neighbour. That is AWS's set, not an omission, and it has a test and a
    comment saying so, because it reads like one.
  • Wildcards work in filter values, matched through the existing ec2FilterAccepts.
    AWS's Example 4 states it outright for this operation: "You can use wildcards with filters,
    so you could specify the value as ?ebserver to find tags with the key webserver or
    Webserver." This is the first site outside DescribeInstanceTypeOfferings to honour them
    (ec2: filter values match exactly everywhere except DescribeInstanceTypeOfferings, where AWS documents wildcards for all of them #697 is the rest).
  • Pagination: MaxResults 5–1000 — AWS's range for this operation, where
    DescribeLaunchTemplateVersions' floor is 1, so the constant cannot be shared. A value
    outside the range is refused, not clamped. The token is DescribeLaunchTemplateVersions'
    wire shape: a decimal offset, InvalidParameterValue on a malformed one, an out-of-range
    offset clamped to an empty last page, and no token on the last page.
  • Deterministic order: sorted by (resourceId, resourceType, key) before paging.

Two decisions worth reading

The scan is deliberately wider than what CreateTags can write. ec2TaggableResource
covers nine prefixes; the scan reads thirteen, adding image, snapshot, launch-template
and fleet — types whose tags arrive through their own create call's TagSpecification.N and
cannot be set through CreateTags at all (#689 adds the snapshot arm, #695 the rest).
Reporting only the writable types would hide tags a caller had successfully applied.
TestEC2_DescribeTags_ScanIsWiderThanCreateTags pins both halves of the asymmetry together,
so #689 has a test to change rather than a surprise to find.

placement-group is the one type carrying a Tags field left out: nothing writes it, and its
records are keyed by group name where AWS's TagDescription reports an ID, so the shared
key-tail helper would report the wrong identifier. (This corrects the plan's own note, which
also listed keypair — EC2KeyPair has no Tags field at all.)

The sort is stricter than AWS, which says its order "might vary" and that applications
should not rely on it. StateManager.List promises no ordering either
(emulator/types.go:123-124), so an offset token over an unordered list could skip or repeat
a tag between pages, and two replays of one recorded request could answer differently. A
deterministic emulator cannot answer one request two ways.

One helper rather than thirteen: ec2StatePrefix(namespace, accountID, region) plus a
{namespace, resourceType} table, since every EC2 key is <ns>:<account>/<region>/<id>. The
resourceType spelling is written beside each namespace rather than derived — sg is
security-group and nat is natgateway, and neither could be computed.

Fail-before

Recorded before the fix, by deleting the dispatch arm and emulator/ec2_describetags.go — i.e.
the pre-#688 tree — with the harness asserting the arm appeared exactly once, go veting the
result so a non-compiling tree would be BROKEN rather than a result, and restoring by file copy
with sha256 byte-identity printed for both files.

=== FAIL-BEFORE: pre-#688 tree (no dispatch arm, no implementation) ===
--- FAIL: TestEC2_DescribeTags_EmptyWhenNothingIsTagged
--- FAIL: TestEC2_DescribeTags_Pagination
--- FAIL: TestEC2_DescribeTags_ScanIsWiderThanCreateTags
--- FAIL: TestEC2_DescribeTags_FiltersAnd
--- FAIL: TestEC2_DescribeTags_FiltersNarrowTheAnswer          (12 subtests)
--- FAIL: TestEC2_DescribeTags_ReportsEveryStoredTag
--- FAIL: TestEC2_DescribeTags_RefusesUndocumentedFilterNames  (4 subtests)
--- FAIL: TestEC2_DescribeTags_RefusesBadPagination            (8 subtests)
=== 8 top-level, 24 leaf failures ===
RESTORE plugin: 5146a888… == 5146a888…
RESTORE impl:   d2c59e02… == d2c59e02…

Every one failed the same way: InvalidAction / EC2Plugin: unknown action DescribeTags,
HTTP 400 (emulator/ec2_plugin.go:245-250).

Tests

Eight unit tests through HTTP, because the whole defect was on the wire, plus an SDK
journey
(test/e2e/journey_ec2_describetags_test.go) — the only tier that shows a real
client's shape agreeing with substrate's, since the SDK decides how Filters serialize and
how tagSet decodes into []types.TagDescription. It walks the region with
ec2.NewDescribeTagsPaginator, whose loop terminates only because the last page carries no
token, and asserts ResourceType against the SDK's own enum constants — a spelling substrate
invented would otherwise arrive as an unknown enum value rather than failing loudly.

Docs

docs/services.md gains a DescribeTags row, a row in the per-operation evaluated/inert
table, and a Finding a resource by tag subsection carrying the wider-than-CreateTags
scan, the no-tag-key rule, and the stricter-than-AWS ordering with its reason. Three
existing statements are now reconciled rather than left standing:

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... (0 issues),
make test (race, ok), make coverage, make docs-reference docs-reference-check docs-versions, npm --prefix docs run build, go vet -C test/e2e ./... and
go test -C test/e2e ./... all clean. docs-versions caught a pinned v0.106.0 in the new
prose on the first pass; it now links the issue instead.

…ources by tag (#688)

DescribeTags reached the dispatcher's default arm and answered InvalidAction/400
while four bundled managed policies granted ec2:DescribeTags — a policy permitted
an operation nothing served.

Five filters, all evaluated, with the wildcards AWS's Example 4 documents for this
operation, and no tag-key — alone in the describe family, because key already asks
that question. MaxResults 5-1000 (refused outside the range, not clamped), an
offset NextToken, and a deterministic (resourceId, resourceType, key) sort, which
is stricter than AWS because StateManager.List promises no ordering and an offset
token over an unordered list could answer one replayed request two ways.

The scan reads thirteen resource types where CreateTags writes nine: an image,
snapshot, launch template or fleet takes its tags from its own create call's
TagSpecification, so reporting only the writable types would hide tags a caller
had successfully applied.
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.84375% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_describetags.go 89.68% 8 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 85a01b4 into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/688-describetags branch August 21, 2026 06:11
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: DescribeTags is unimplemented

1 participant