Skip to content

CloudFormation: an intrinsic nested inside a structured property is never resolved #526

Closed

Description

@scttfrdmn

Found while re-running #516's reproduction against the released v0.87.1 binary, using the reporter's own ecs_worker.yml shape. Independent of #516 and #517; predates both. The ECS half of what I found while probing this is split out as its own defect — see below.

What happens

resolveValue (emulator/betty_cfn.go:3107) resolves a value that is an intrinsic: a scalar, or a single-key map whose key is Ref/Fn::Sub/Fn::Join/Fn::Select/Fn::Split/Fn::Base64/Fn::GetAtt/Fn::If. Nothing walks into a map or list to resolve intrinsics nested within it. So wherever a deploy path forwards a structured property whole, any intrinsic inside it survives to the plugin unresolved.

For ECS it is stored as a literal object:

"Command": {"Fn::Split": [",", "python,-m,worker"]}

For DynamoDB it is a hard failure — the plugin's typed struct rejects the object, which at least reports honestly now that #519 is fixed:

aws cloudformation create-stack --stack-name ddbnested --template-body \
  '{"Parameters":{"PK":{"Type":"String","Default":"pk"}},"Resources":{"T":{
     "Type":"AWS::DynamoDB::Table","Properties":{"TableName":"nested-probe",
     "BillingMode":"PAY_PER_REQUEST",
     "KeySchema":[{"AttributeName":{"Ref":"PK"},"KeyType":"HASH"}],
     "AttributeDefinitions":[{"AttributeName":{"Ref":"PK"},"AttributeType":"S"}]}}}}'

aws cloudformation describe-stack-resources --stack-name ddbnested
  → CREATE_FAILED
    SerializationException: Failed to parse request: json: cannot unmarshal object
    into Go struct field DynamoDBAttributeDefinition.AttributeDefinitions.AttributeName
    of type string

{"Ref": "PK"} inside KeySchema is ordinary CloudFormation. Real CloudFormation resolves intrinsics at any depth in a property value.

It is per-property, not universal

AWS::EC2::LaunchTemplate resolves nested intrinsics correctly, because betty_cfn_v77_plugins.go:34 walks LaunchTemplateData key by key and calls resolveStringProp/resolveStringList on each. That is the distinction:

  • Walked → intrinsics resolve. LaunchTemplateData.ImageId via {"Ref": …} — verified working.
  • Forwarded whole → intrinsics survive. ContainerDefinitions[].Command, KeySchema[].AttributeName, AttributeDefinitions[].AttributeName — verified broken.

So the gap tracks how each deploy path happens to have been written, which means a consumer cannot predict which of their properties will resolve.

Shape of a fix

A general resolveNested(v interface{}, cctx *cfnContext) interface{} that walks maps and lists, resolving any node resolveValue recognizes and leaving everything else structurally intact, applied at each verbatim-forwarding site. Two things need care:

Acceptance criteria

  • An intrinsic nested at any depth inside a structured property resolves — at minimum ContainerDefinitions[].Command, ContainerDefinitions[].Environment[].Value, KeySchema[].AttributeName, AttributeDefinitions[].AttributeName.
  • The DynamoDB {"Ref": "PK"}-in-KeySchema template above reaches CREATE_COMPLETE and the table's key schema names the resolved attribute.
  • A property whose keys are user data (ECS logConfiguration.options, resource Tags values are fine but keys are user-supplied) is not rewritten by the walk.
  • A test asserting the reporter's ecs_worker.yml container command resolves to a list rather than an Fn::Split object (may depend on CloudFormation: Fn::Split resolves to its first element only, so a split list silently loses everything after the first item #521).
  • docs/services.md states that nested intrinsics resolve, replacing any per-property caveat.

Related

Activity

  1. added
    type: bug
    priority: high
    on Aug 3, 2026
  2. changed the title [-]CloudFormation: an intrinsic nested inside a structured property is never resolved, and ECS ContainerDefinitions are forwarded in the wrong case[/-] [+]CloudFormation: an intrinsic nested inside a structured property is never resolved[/+] on Aug 3, 2026
  3. added this to the v0.88.0 milestone on Aug 3, 2026
  4. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Milestoned to v0.88.0. Recording the dependency and three implementation constraints found while planning, since a naive fix gets each of them wrong.

    Blocked on #521. The resolver returns a string and does not recurse; those are the same root cause. Resolving a nested intrinsic means splicing a nested Fn::Split into a list position, which needs #521's list-returning resolver first. Fixing this one alone would resolve a nested !Split to its first element — trading a silent drop for a silent truncation.

    Constraint 1: a multi-key map is not an intrinsic. A single-key map whose key is a recognized Fn::/Ref name resolves; a map with two or more keys must be left alone even if one of them is Ref, because that is user data, not an intrinsic. A walk that checks if v["Ref"] != nil rather than len(v) == 1 && v["Ref"] != nil corrupts any user-supplied map that happens to contain a Ref key.

    Constraint 2: keys are never rewritten. This issue is about values. Rewriting keys is #527's job, and conflating the two is how logConfiguration.options gets mangled — its keys are user data (awslogs-group, awslogs-stream-prefix) and must survive verbatim.

    Constraint 3: Fn::If yielding AWS::NoValue must remove the property, as CloudFormation does, not leave an empty string. This is on the critical path rather than a nicety: the reporting consumer's template writes

    Command: !If [HasCommand, !Split [",", !Ref CommandCSV], !Ref "AWS::NoValue"]

    and an empty-string command on a container definition is a different observable from an absent one.

    Where the fix applies — and where it must not. The gap is per-property, which is why a consumer cannot predict it: deployEC2LaunchTemplate (emulator/betty_cfn_v77_plugins.go:34) enumerates LaunchTemplateData key by key and therefore does resolve nested intrinsics, while ContainerDefinitions (betty_cfn_v21_plugins.go:150) and DynamoDB's KeySchema/AttributeDefinitions/ProvisionedThroughput/GlobalSecondaryIndexes/LocalSecondaryIndexes/StreamSpecification (betty_cfn.go:1870-1890) are forwarded whole. Those forwarding sites are where a resolveNested goes.

    It should not be applied blindly to every props map. An IAM policy document is a property whose interior is meaningful in its own right and needs a separate decision.

    A guard worth stating, because it is the highest-value mutation test. DynamoDB's verbatim forwarding is correct on the key-naming axis — the DynamoDB API is natively PascalCase, so KeySchema/AttributeName are exactly right on the wire. Only its values need resolving. A generic case-converting walk applied here would break DynamoDB, which is why #527's mapping must be a per-service table and why "apply the ECS key table to DynamoDB's properties" is one of the mutants this fix must be shown to catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions