Repository navigation
fix(cloudformation): expand YAML short-form intrinsics, report a refused resource (#516) - #523
Merged
Merged
Conversation
…sed resource (#516) A template written with !Ref, !Sub or !If deployed with unresolved literals where a value should be. go.yaml.in/yaml/v3 has no notion of CloudFormation's tag shorthands, so it dropped the tag and kept the node value: `!Sub 'x-${P}'` reached the resolver as the plain string "x-${P}", indistinguishable from a literal the template really did intend, and `!If [C, a, b]` arrived as the raw array ["C", "a", "b"]. The Fn::-prefixed long forms were unaffected throughout, so this was purely tag resolution. The template is now decoded into a yaml.Node, whose .Tag survives, and every recognized shorthand is rewritten into its long form before the node is decoded. The walk is depth-first, children before parents, because the tags nest: `!Not [!Equals [!Ref VpcId, '']]` is three levels deep and is the most common condition idiom in real templates. !GetAtt is the one irregular expansion, split on the first period only. An unrecognized tag keeps its value and logs a WARN rather than being dropped, since a macro may introduce one substrate has never heard of. Three defects surfaced behind it, each reachable only once the tags expand: - Fn::Sub's `${!Literal}` escape was never implemented, so `${!Count.Index}` would have resolved as a ref named "!Count.Index". - A parameter declared `Default: ''` was treated as having no default, leaving it undeclared so Ref echoed its own name back — which inverts the conventional `!Not [!Equals [!Ref X, '']]` optional-parameter test. Found by deploying a real template as a fixture, not by reading the code. - Conditions were evaluated by iterating a Go map, so a condition referencing another read the referent's zero value whenever it was reached first: the same template deployed differently from run to run. They now resolve on demand, and a cycle resolves to false. Separately (#519), the deployer never looked at a response status, only at the error return. S3 and IAM report a refusal as a 4xx response with a nil error — the shape a real endpoint puts on the wire — while EC2/ECS/Logs/SQS return an *AWSError. Only the second was inspected, so every S3 and IAM resource failure in a stack was swallowed and reported CREATE_COMPLETE for a resource that does not exist. That is #516's own reproduction. One helper in dispatch now derives the failure from either convention, lifting the plugin's error code out of the body so the reason names what went wrong. Compatibility: a resource that genuinely fails now reports CREATE_FAILED where it reported CREATE_COMPLETE.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 3, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #516
Closes #519
parseCFNTemplateunmarshalled YAML straight into the template struct, andgo.yaml.in/yaml/v3has no notion of CloudFormation's tag shorthands: it dropsthe tag and keeps the node value. So
!Sub 'short-${P}'reached the resolver asthe literal
short-${P}— indistinguishable from a string the template reallydid intend — and
!If [C, a, b]arrived as the raw array["C","a","b"], whichis what the reporting consumer saw stamped verbatim into an ECS task-definition
family. Nothing downstream was ever handed anything to resolve. The
Fn::longforms worked correctly throughout.
The fix decodes into a
yaml.Node, whose.Tagsurvives, rewrites everyrecognized shorthand into its long-form mapping, and decodes that. All eighteen
are handled, and the walk is depth-first, children before parents, because
the tags nest —
!Not [!Equals [!Ref VpcId, '']]is three levels and is the mostcommon condition idiom in real templates.
!GetAttis the one irregular form(dotted string, split on the first period only, per AWS's own
myELB.SourceSecurityGroup.OwnerAliasexample). An unrecognized tag keeps itsvalue and logs a
WARN: dropping it silently is the defect being fixed, andrefusing the template would reject one real CloudFormation accepts.
Three defects behind it, each reachable only once the tags expand
Fn::Sub's${!Literal}escape was never implemented. The reporter'sec2_worker.ymlcontains${!Count.Index}, which would have resolved as a refnamed
!Count.Index. Unreachable before the expander, which is why it shipshere.
Default: ''was treated as no default at all, so the parameter was leftundeclared and
Refechoed its own name back — which inverts theconventional
!Not [!Equals [!Ref X, '']]optional-parameter test: a parameterthe caller never set reads as set. 21 occurrences across the reporter's five
templates. Found by deploying one of them as a checked-in fixture, not by
reading the code.
another via
{"Condition": "Other"}read the referent's zero value whenever itwas reached first: the same template deployed differently from one run to the
next, which is the one outcome an emulator built on deterministic replay must
never produce. They now resolve on demand, and a cycle resolves to
false.Names are additionally walked sorted, which matters only for a cycle running
through
Fn::Not— that resolves its two members to opposite values, soabsent the sort the answer would still depend on map order.
#519 — a refused resource was reported CREATE_COMPLETE
The deployer set a resource's error only when the dispatched request returned a
non-nil
error, and never read the response status. Plugins signal a clienterror two ways, both in wide use: S3 (58 sites) and IAM (162) return a 4xx
response with a nil error — the shape a real endpoint puts on the wire — while
EC2 (49), ECS (27), Logs (20) and SQS (5) return an
*AWSError. Only the secondwas inspected, so every S3 and IAM resource failure in a stack was swallowed.
That is #516's own reproduction: invalid bucket name, no bucket, and a stack
reporting success.
cfnDispatchErrornow derives the failure from either convention, appliedcentrally in
dispatchso all 31 recording sites became correct without beingindividually edited, and lifts the plugin's own code out of the body so the
reason reads
InvalidBucketName: The specified bucket is not valid.rather thana status number.
deployS3Bucketalso stops discarding its response and returnsearly rather than configuring versioning on a bucket that was refused — that
follow-up could not corrupt the recorded reason (its result was discarded too),
but it did put a
PUT ?versioningrefused withNoSuchBucketinto the logsubstrate replays.
Rollback is deliberately not changed: substrate records the failure per
resource and carries on where real CloudFormation would roll back. Filed as #520.
Compatibility
A resource that genuinely fails now reports
CREATE_FAILEDwhere it reportedCREATE_COMPLETE. A test asserting the old status was asserting a defect, butit will still turn red. Stack status is unchanged.
Expansion is not resolution:
!FindInMap,!ImportValue,!Cidrand!GetAZsnow expand to long forms the resolver still ignores and hit the same fallback the
long forms already did (#522 —
Fn::FindInMapneeds aMappingsmodel thetemplate struct does not have).
Fn::Splitstill yields only its first element(#521). The docs say both, so "expanded" is not read as "resolved". None of the
reporter's templates use the four unresolved intrinsics; one does use
!Split.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race), the docs targets,npm --prefix docs run build, andthe
test/e2emodule — all green. Every new or changed function is at 100%statement coverage.
Mutation testing, 24 mutants: 23 caught. Four were worth more than a tally.
native-tag-always-strsurvived because the branch it mutated was unreachable —resolved by deleting the code, not by adding a test.
conditions-unsorted-lazy-walksurvived twice: the lazy accessor, not the sort, is what makes a chain
order-independent, so the sort is load-bearing only for a negated cycle, and
even with that case added the divergence appears in the member reached second,
which the test was not asserting. The remaining survivor is a genuine equivalence
with a written proof at the call site, settled by the AWS docs stating
Fn::Ifisnot supported inside a
Conditionsentry.End to end over the wire against both a fixed and a pre-fix binary, so the claims
are demonstrated in both directions: pre-fix gives
short-${p},["HasP","role-${P}","role-none"]andCREATE_COMPLETEfor the bad bucket;post-fix gives
short-live,role-live, the GetAtt ARN, the${Count.Index}literal, and
CREATE_FAILED/InvalidBucketName.