Skip to content

fix(cfn): resolve intrinsics at any depth, and map ECS member names (#526, #527) - #533

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/526-527-nested-intrinsics-ecs-keys
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/526-527-nested-intrinsics-ecs-keys

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

Two priority: high defects with the same cause and the same symptom shape — substrate returns HTTP 200 while the observable a caller parses is wrong or empty.

Closes #526
Closes #527

#526 — intrinsics never resolved below the top level

resolveValue resolves a value that is an intrinsic; nothing walked into a map or a list to resolve one nested within. So a deploy path that forwarded a structured property whole handed the plugin {"Ref": "PK"} as a literal object: DynamoDB's typed plugin rejected it —

SerializationException: Failed to parse request: json: cannot unmarshal object
into Go struct field …AttributeDefinitions.AttributeName of type string

— and the resource CREATE_FAILED, while an untyped plugin stored the object and echoed it back. Which of a consumer's properties resolved depended on how each deploy path happened to have been written: LaunchTemplateData and security-group rules enumerate their members key by key, ContainerDefinitions/KeySchema/AttributeDefinitions were forwarded verbatim.

resolveNested walks a property and returns a structurally identical value with every intrinsic resolved. Four rules a naive walk gets wrong, each pinned by a test:

resolveNested returns interface{} rather than resolveValue's string, so a member that is a list-valued intrinsic keeps its list instead of inheriting #521's scalar-context rejoin. A literal passes through untouched, so {"ContainerPort": 8080} stays the number 8080.

Applied at the verbatim-forwarding sites, and at three more the audit found where a .(string) assertion was silently dropping intrinsic-valued members — the same defect wearing a different plugin:

Path What was dropped
ECS ContainerDefinitions everything nested
DynamoDB KeySchema, AttributeDefinitions, ProvisionedThroughput, GlobalSecondaryIndexes, LocalSecondaryIndexes, StreamSpecification resource CREATE_FAILED
ACM SubjectAlternativeNames a !Ref- or !Split-valued SAN
MSK BrokerNodeGroupInfo.InstanceType, .ClientSubnets a !Ref-valued subnet list — how a template names subnets far more often than as literals
FSx SubnetIds, Tags Value: !Sub '${AWS::StackName}-data', the single most common way a template writes a tag

MSK's ClientSubnets is overwritten only when it resolves to something, so an absent property keeps its [] default rather than becoming a JSON null — different requests to a decoding consumer.

#527 — ECS container definitions carried CloudFormation's casing onto the wire

CloudFormation spells a container's members in PascalCase where the ECS API spells them camelCase. ContainerDefinitions is untyped both in RegisterTaskDefinition's request and in state, so there was nothing to reject them: the stack reached CREATE_COMPLETE, DescribeTaskDefinition answered 200, and --query 'taskDefinition.containerDefinitions' returned [{}] — every member present under a name no SDK reads. A direct RegisterTaskDefinition call was never affected; the mismatch was introduced by the deploy path alone.

The mapping is an explicit table of all 42 ContainerDefinition members plus the 11 nested types (environment, secrets, portMappings, logConfiguration, mountPoints, volumesFrom, healthCheck, ulimits, dependsOn, extraHosts, systemControls), each verified member by member against its own API reference page. Two decisions worth stating:

  • A table, not a first-letter-lowering function — which would be right for all 42 members today. Only a table can tell "not mapped" from "mapped to itself", so a member ECS adds later passes through verbatim rather than being renamed to something the API does not accept. TestECSContainerDefinitionKeys_MatchAPICase asserts the table against the rule, so the rule's safety is kept without its fragility.
  • Per-service, never generic. DynamoDB, ACM and MSK are natively PascalCase; a generic converter is precisely the change that would break them. logConfiguration.options and dockerLabels are named by their parent's table and then left whole, their keys being user data.

Tests

Every new gate was confirmed to fail with the fix reverted. Assertions are on raw JSON bytes where the defect is a member's name — a Go round-trip cannot see a casing defect, since encoding/json matches a field case-insensitively absent an exact match, so DynamoDB's PascalCase struct reads "keySchema" perfectly well and a read-back agrees with the defect. The DynamoDB guard therefore reads the bytes the deploy path put on the wire, out of the event store.

Mutation testing

18 mutants, 16 CAUGHT. Both survivors are accounted for rather than left open:

  • The ECS key table also applied to DynamoDB's properties — SURVIVED, and provably equivalent: the two vocabularies are disjoint (verified by set intersection over the table and DynamoDB's member names), so the walk is structural identity. The mutant that matters here is a generic converter, and M8b — first-letter-lowering applied to DynamoDB — is CAUGHT by the new raw-body assertions.
  • The two ECS passes run in the opposite order — SURVIVED, and they commute: ecsRewriteKeys touches keys only, through tables containing no intrinsic name, so it cannot change whether a map is an intrinsic; resolveNested replaces values only, so it cannot change which table is selected. The doc comment was corrected to say so rather than claim an ordering constraint that does not exist.

One mutant found a real test-design defect and one found a redundant guard, both fixed rather than accepted:

  • ecsUserDataMembers was a no-op — a member with no nested table is already never descended into, so the guard had no observable effect. Removed, and the reasoning moved to ecsNestedContainerKeys, where membership is the actual decision: options and dockerLabels must never appear there.
  • The DynamoDB guard passed under a generic converter, for the encoding/json reason above. It now asserts on the wire bytes.

Verified over the wire

Against substrate server, the three reproductions from the issues:

$ aws ecs describe-task-definition --task-definition json-family \
    --query 'taskDefinition.containerDefinitions'
[{"name": "worker", "image": "python:3.11"}]          # was [{}]

$ aws dynamodb describe-table --table-name nested-probe \
    --query 'Table.KeySchema[0].AttributeName'
"pk"                                                   # was CREATE_FAILED

$ aws ecs describe-task-definition --task-definition split-family \
    --query 'taskDefinition.containerDefinitions[0].command'
["python", "-m", "worker"]                             # was ["python,-m,worker"]

$ … --query 'taskDefinition.containerDefinitions[0].logConfiguration'
{"logDriver": "awslogs", "options": {"awslogs-group": "/ecs/probe", "awslogs-region": "us-west-2"}}

Docs

docs/services.md §Templates gains the invariant a consumer needs to predict behaviour — intrinsics resolve at any depth — with the two rules that bound the walk (single-key maps only; keys are never rewritten by resolution) and the note that a resolved scalar is a string while a literal is never retyped. The AWS::NoValue paragraph now covers the whole-property case, not only the list position. make docs-reference produces no diff; no plugin was added.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0 issues, make test (race), make docs-reference docs-reference-check docs-versions, npm --prefix docs run build, go vet -C test/e2e ./..., go test -C test/e2e ./... — all green.

…526, #527)

resolveValue resolves a value that *is* an intrinsic; nothing walked into a map
or a list to resolve one nested within. A deploy path that forwarded a structured
property whole therefore handed the plugin `{"Ref": "PK"}` as a literal object —
DynamoDB's typed plugin rejected it with a SerializationException and the
resource CREATE_FAILED, while an untyped plugin stored it and echoed it back.
Which of a consumer's properties resolved depended on how each deploy path
happened to have been written.

resolveNested walks a property and returns a structurally identical value with
every intrinsic resolved. Four rules a naive walk gets wrong: only a single-key
map is an intrinsic (a multi-key map is user data even when one key is `Ref` —
the same map-iteration nondeterminism #521 fixed a level up); a list-valued
intrinsic in a list position splices its elements; an Fn::If yielding
AWS::NoValue removes the property rather than leaving an empty string; and
resolution never rewrites a key, which is what would mangle a
logConfiguration.options whose keys are user data.

Applied at the verbatim-forwarding sites, plus the three deploy paths that
asserted a property was a literal string and dropped anything else — ACM's
SubjectAlternativeNames, MSK's BrokerNodeGroupInfo and FSx's SubnetIds and Tags,
so `Value: !Sub '${AWS::StackName}-data'` now reaches the API.

For #527, CloudFormation spells a container's members in PascalCase where the ECS
API spells them camelCase, and ContainerDefinitions is untyped both in
RegisterTaskDefinition's request and in state, so nothing rejected them: the
stack reached CREATE_COMPLETE, DescribeTaskDefinition answered 200, and
`--query 'taskDefinition.containerDefinitions'` returned [{}]. The mapping is an
explicit table of all 42 ContainerDefinition members plus the 11 nested types,
verified against each type's own API reference page — a table rather than a
first-letter-lowering function because only a table can tell "not mapped" from
"mapped to itself", and per-service because DynamoDB, ACM and MSK are natively
PascalCase and a generic converter is what would break them.
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/betty_cfn.go 87.77% 6 Missing and 5 partials ⚠️
emulator/betty_cfn_v21_plugins.go 95.45% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 0532f94 into main Aug 3, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/526-527-nested-intrinsics-ecs-keys branch August 3, 2026 09:34
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