Repository navigation
Description
Thanks for #483 — CFN over the wire works, and #484/#485 both verify as completely
fixed on 0.87.0. This is the larger of two things I hit immediately afterwards.
The defect
parseCFNTemplate resolves the Fn::-prefixed long forms correctly but silently
discards the YAML short-form tags (!Sub, !Ref, !If, !GetAtt, !Join),
leaving the raw scalar behind as a literal. Two stacks differing only in that,
against ghcr.io/scttfrdmn/substrate:0.87.0:
shortf: BucketName: !Sub 'short-${P}' -> PhysicalResourceId = 'short-${p}'
longf: BucketName: {Fn::Sub: 'long-${P}'} -> PhysicalResourceId = 'long-live'
P was passed as live in both. The long form substitutes; the short form keeps
${P} verbatim (S3 then lowercases it). Same for !Ref:
LogGroupName: !Ref P yields the literal string P, where Ref: P yields zz.
And !If:
ShortIf: !If [C, a, b] -> ["C", "a", "b"] (the raw array; no branch chosen)
LongIf: {Fn::If: [C,a,b]} -> correct branch, verified on both a true and a false condition
So the intrinsics engine is fine — Fn::If picks the right branch either way. It is
tag resolution that is missing.
Worth noting the stack still reports success: short-${p} is not a valid bucket
name and no bucket was created, but the stack reached CREATE_COMPLETE and
describe_stack_resources reported CREATE_COMPLETE for the resource.
Cause
emulator/betty_cfn.go:3358 — parseCFNTemplate unmarshals straight into
cfnTemplate:
func parseCFNTemplate(cfn string) (*cfnTemplate, error) {
var tmpl cfnTemplate
if err := json.Unmarshal([]byte(cfn), &tmpl); err == nil { ... }
if err := yaml.Unmarshal([]byte(cfn), &tmpl); err == nil { ... }go.yaml.in/yaml/v3 (imported at betty_cfn.go:16) has no notion of the
CloudFormation tag shorthands, so it drops the tag and keeps the node value. Confirmed
against the library directly, independent of substrate:
src := `
Resources:
R:
Type: AWS::S3::Bucket
Properties:
Short: !Sub 'x-${P}'
Long:
Fn::Sub: 'x-${P}'
ShortIf: !If [C, a, b]
LongIf:
Fn::If: [C, a, b]
`
var m map[string]interface{}
yaml.Unmarshal([]byte(src), &m)"Short": "x-${P}", // tag gone, scalar kept
"Long": { "Fn::Sub": "x-${P}" }, // intact
"ShortIf": ["C", "a", "b"], // tag gone, sequence kept
"LongIf": { "Fn::If": ["C", "a", "b"] } // intactBecause the tag vanishes at unmarshal time, nothing downstream can tell a !Sub
string from a literal — the resolver is never given anything to resolve.
The usual fix is to decode into yaml.Node and rewrite tagged nodes to their
Fn::/Ref mapping equivalents before unmarshalling, since yaml.Node preserves
.Tag. The shorthands and their expansions:
| Short | Long |
|---|---|
!Ref x |
{"Ref": "x"} |
!Sub s |
{"Fn::Sub": s} |
!GetAtt a.b |
{"Fn::GetAtt": ["a","b"]} — string-splits on ., unlike the others |
!If [c,a,b] |
{"Fn::If": [c,a,b]} |
!Equals, !Not, !And, !Or, !Join, !Select, !Split, !FindInMap, !Base64, !ImportValue, !Cidr, !GetAZs, !Condition |
{"Fn::<Name>": <value>} (!Condition → {"Condition": v}) |
!GetAtt is the one irregular case.
Why it matters
This is more consequential than it first looks, because the short forms are what
people actually write. Every template in
parsl-aws-provider's
templates/cloudformation/ uses them — 29 to 47 occurrences each across
bastion.yml, ecs_worker.yml, lambda_worker.yml, ec2_worker.yml and vpc.yml
— and they are conventional AWS YAML, not an unusual style. Deploying
ecs_worker.yml yields a task definition whose ARN embeds an unevaluated condition
array verbatim:
arn:aws:ecs:us-east-1:123456789012:task-definition/["HasTaskFamily","TaskFamily","parsl-task-${WorkflowId}-${JobId}"]:1
from Family: !If [HasTaskFamily, !Ref TaskFamily, !Sub 'parsl-task-${WorkflowId}-${JobId}'].
A consumer sees CREATE_COMPLETE and reasonably concludes the stack deployed, so
this fails in the least helpful direction — silently, with a success status. Anyone
converting a suite from moto (which handles both forms) to substrate would hit it on
their first real template.
Reproduce
import boto3
E = "http://localhost:4566"
cf = boto3.client("cloudformation", endpoint_url=E, region_name="us-east-1")
for name, prop in [("shortf", "BucketName: !Sub 'short-${P}'"),
("longf", "BucketName:\n Fn::Sub: 'long-${P}'")]:
cf.create_stack(StackName=name, TemplateBody=f"""
Parameters:
P:
Type: String
Default: unset
Resources:
B:
Type: AWS::S3::Bucket
Properties:
{prop}
""", Parameters=[{"ParameterKey": "P", "ParameterValue": "live"}])
cf.get_waiter("stack_create_complete").wait(StackName=name)
r = cf.describe_stack_resources(StackName=name)["StackResources"][0]
print(name, "->", repr(r["PhysicalResourceId"]))
# shortf -> 'short-${p}' expected 'short-live'
# longf -> 'long-live' correctFiled alongside a separate account-partition issue affecting the same code path.
Activity
fix(cloudformation): expand YAML short-form intrinsics, report a refu…
chore(release): v0.87.1 (#525)
scttfrdmn commentedon Aug 3, 2026
Confirmed, fixed, and released in v0.87.1 (PR #523). Thank you for the diagnosis — it was correct in every particular, including the part that took the longest to see from the outside.
Your diagnosis was right
I reproduced it standalone against
go.yaml.in/yaml/v3 v3.0.5before touching substrate, and got exactly what you describe:!Sub 'x-${P}'unmarshals to the plain string"x-${P}",!If [C, a, b]to the raw array["C","a","b"], and everyFn::long form comes through intact. Youryaml.Nodesuggestion is the fix — walking the node tree printedcustom tag "!Sub" kind=8,"!If" kind=2,"!GetAtt" kind=8, so the tag is available at exactly the point it needed to be.Your expansion table is correct as written,
!GetAttincluded as the irregular one. It is implemented as you had it: split the dotted string on the first period only, because an attribute name can itself contain periods — AWS's own example maps!GetAtt myELB.SourceSecurityGroup.OwnerAliasto["myELB", "SourceSecurityGroup.OwnerAlias"]. A!GetAttalready written in sequence form passes through untouched.Three things the fix needed that the issue did not have
The walk has to be depth-first, children before parents. Your own templates nest three levels:
lambda_worker.yml:83hasHasVpcConfig: !Not [!Equals [!Ref VpcId, '']], and!If [C, !Ref X, !Ref 'AWS::NoValue']appears 14 times across the five files. Expanding a parent before its children leaves the inner tags in a node the parent has already consumed. This is the mutant that a naive implementation fails.${!Literal}shipped with it, because your templates make it reachable.ec2_worker.yml:124writes!Sub 'parsl-worker-${WorkflowId}-${BlockId}-${!Count.Index}'.substituteTemplatehad no handling for the documented${!escape — it would have resolved a ref named!Count.Indexand emitted the name back. That was unreachable before, since the whole!Subwas being discarded; the expander makes it live, so the escape had to land in the same change.${!Count.Index}now renders as the literal${Count.Index}.Expansion is not resolution, for four of the eighteen.
!FindInMap,!ImportValue,!Cidrand!GetAZsnow expand to long forms the resolver still ignores, and hit the same fallback the long forms already got. Expanding them is still right — the invariant this issue is really about is that the two syntaxes behave identically — but I do not want "expanded" read as "resolved". None of your five templates use any of the four (I checked all of them:!Ref×142,!If×24,!Equals×21,!Sub×19,!Not×18,!GetAtt×12,!Select×2,!Split×1,!Join×1,!Condition×1,!And×1), so you are not affected. Tracked in #522;Fn::FindInMapadditionally needs aMappingsmodel the template struct does not have.An unrecognized tag is now kept with a
WARNnaming it, rather than dropped or refused: silently dropping is the defect being fixed, and refusing would reject templates real CloudFormation accepts.Your aside about the stack still reporting success was a second, separate defect
You noted almost in passing that the stack said
CREATE_COMPLETEwith no bucket. That is not a consequence of the tag bug — it is its own defect, and a worse one. The deployer set a resource's error only when the dispatched request returned a non-nil Goerror, and never inspected the response status. Plugins signal a client error 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 error value. Only the second was ever checked, so every S3 and IAM resource failure in a stack was swallowed.Filed as #519 and fixed in the same PR: the failure is now derived from either convention, centrally in
dispatch, with the plugin's own code lifted from the body — so your invalid bucket name now reportsCREATE_FAILEDwithInvalidBucketName: The specified bucket is not valid.rather than success. This is a compatibility note for anyone else: a resource that genuinely fails now reportsCREATE_FAILEDwhere it reportedCREATE_COMPLETE. Substrate still does not roll the stack back — real CloudFormation would — which is #520.Two more found by deploying your templates as fixtures
I checked
ecs_worker.ymlin as testdata rather than writing a synthetic template, and it surfaced two defects that reading the code did not:Default: ''was treated as no default at all, so such a parameter was left undeclared,Refechoed the parameter's own name back, and!Not [!Equals [!Ref X, '']]inverted — a parameter the caller never set read as set, and the template took the wrong branch silently.Default: ''is how an optional parameter is spelled, 21 times across your five templates, so this one would have bitten you immediately after the tag fix landed.{"Condition": "Other"}read the referent's zero value whenever it was evaluated first. The same template deployed differently from run to run — nondeterminism, which is the one thing an emulator built on deterministic replay must never produce. Conditions now resolve on demand and are cached for the deployment.Still not resolved, in your templates specifically
Fn::Splityields only its first element (CloudFormation: Fn::Split resolves to its first element only, so a split list silently loses everything after the first item #521).ecs_worker.yml:208writes!Split [',', !Ref Command]for a container command, so after this fix you get one element where a list is meant. The resolver returns a string, so this needs a list-returning sibling rather than a patch.Commandabove is nested insideContainerDefinitions, and nothing walks into a forwarded property.AWS::EC2::LaunchTemplateresolves nested intrinsics correctly because its deploy path enumerates them explicitly, so the gap is per-property.ContainerDefinitionsreach the ECS plugin in CloudFormation's PascalCase (ECS: a CloudFormation-deployed task definition's ContainerDefinitions keep CloudFormation's PascalCase keys #527), also found against your template.describe-task-definitionreturnscontainerDefinitions: [{}]— the data is stored underImage/Namewhere the API and every SDK expectimage/name. The family, revision and ARN are all correct; only the container list reads empty.All three affect
ecs_worker.yml. #521 and #526 want fixing together, since a nested!Splitis the case where returning one element is wrong.fix(plugins): an unimplemented operation is refused by its protocol, …