Skip to content

fix(cloudformation): generate AWS-style names for unnamed resources - #2536

Merged
vieiralucas merged 5 commits into
mainfrom
fix/cfn-generated-physical-names
Sep 15, 2026
Merged

vieiralucas merged 5 commits into
mainfrom
fix/cfn-generated-physical-names

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Sep 15, 2026

Copy link
Copy Markdown
Member

Summary

Resources whose name property a template leaves out were named after their bare logical id (Queue, MyBucket, ...). Two stacks built from one template in the same account (dev and prod stacks, or one stack set deployed to two regions) collided on every such resource, and an unnamed S3 bucket got an invalid uppercase name.

CloudFormation now generates names the way AWS does:

  • New naming module: {StackName}-{LogicalId}-{SUFFIX} with a random 13-character suffix, truncated to each type's documented name limit (e.g. 32 for load balancers, 63 for buckets and RDS identifiers, 80 for queues), lowercased where the type requires it (S3, RDS, ElastiCache, ECR, Glue, OpenSearch, CodeArtifact domains), _ instead of - where hyphens are invalid (Cognito identity pools, AppSync data sources). State machines and secrets are {LogicalId}-{SUFFIX}; nested stacks are {ParentStack}-{LogicalId}-{SUFFIX}.
  • Applied across the provisioners that defaulted to the logical id or to ad-hoc cfn-* / uuid names: about 130 sites, including RDS instances and clusters, Redshift/DocDB/Neptune clusters, ElastiCache, SES, API Gateway keys, Route 53 and CloudFront caller references.
  • Unnamed FIFO queues and topics (FifoQueue / FifoTopic: true) get the required .fifo ending; previously such a queue was silently created non-FIFO.
  • Updates keep names: an update that still leaves the name out keeps the resource's current name. Per-type update handlers fall back to the stored name (CodeCommit, CodeArtifact, Elastic Beanstalk, Amazon MQ, CloudWatch alarms, Backup plans, Organizations). Types updated by re-provisioning, and ECS task definitions (which now register the next revision of the same family), recover the name from the physical id; names older builds generated (logical id, cfn-*, {LogicalId}-{8 hex}) are recognized so an upgrade does not rename resources.
  • Replacement with UpdateReplacePolicy: Retain gives the new resource a fresh name, so it never overwrites the retained one.

Test plan

  • cargo nextest run -p fakecloud-cloudformation --lib: 427 passed (naming shape, truncation, lowercase, separators, legacy names, update keeps name, re-provision keeps name, retained replacement renames, task definition revisions, FIFO endings)
  • New e2e cloudformation_generated_names.rs: two stacks from one unnamed template get distinct names (queue, FIFO queue, lowercase bucket, topic); an update keeps the generated name
  • All 137 CloudFormation/SAM e2e tests pass locally; three that asserted logical-id names now assert generated names (Elastic Beanstalk version/template, ASG, SAM role and rule)
  • cargo nextest run -p fakecloud-conformance --test cloudformation --test cloudcontrol --test apigateway
  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt

Surface

  • Docs: website/content/docs/services/cloudformation.md gains a "Generated names" entry; the gotcha about unnamed resources colliding is replaced by one about explicitly named resources being per account rather than per region.
  • No API surface, count, or introspection change, so README, SDKs, repo description and conformance baseline are unchanged.

Summary by cubic

CloudFormation now generates AWS-style physical names for resources whose name properties are omitted instead of using logical IDs or ad-hoc names. This prevents collisions between stacks and produces valid service-specific names, including for S3 buckets.

Bug Fixes

  • Uses {StackName}-{LogicalId}-{SUFFIX} with service-specific length, case, and separator rules; state machines and secrets use {LogicalId}-{SUFFIX}, while nested stacks include the parent stack name.
  • Adds the required .fifo suffix to unnamed FIFO queues and topics.
  • Preserves generated names across updates, re-provisioning, ECS task-definition revisions, and upgrades from recognized legacy names.
  • Gives replacements a fresh name when UpdateReplacePolicy: Retain preserves the old resource.
  • Keeps explicitly configured names unchanged and documents the new behavior.

Coverage

  • Adds unit and end-to-end tests for name generation, truncation, formatting, FIFO resources, updates, replacements, and legacy-name recovery.

Written for commit 282e2ab. Summary will update on new commits.

Review in cubic

Resources whose name property a template leaves out were named after
their bare logical id, so two stacks from one template in the same
account (a stack set in two regions, dev and prod stacks) collided on
every such resource, and an unnamed S3 bucket got an invalid uppercase
name.

- New naming module: {StackName}-{LogicalId}-{SUFFIX} with a random
  13-character suffix, truncated to each type's name limit and
  lowercased where the type requires it; state machines and secrets
  omit the stack name; nested stacks are named after their parent
- Applied across the provisioners that defaulted to the logical id or
  to ad-hoc cfn-* / uuid names (RDS, Redshift/DocDB/Neptune clusters,
  ElastiCache, SES, Route 53 and CloudFront caller references, ...)
- An unnamed FIFO queue gets the required .fifo ending
- Updates that leave the name out keep the resource's current name
  instead of re-deriving one (CodeCommit, CodeArtifact, Elastic
  Beanstalk, Amazon MQ, CloudWatch alarms, Backup plans, Organizations)
- e2e tests that asserted logical-id names now assert generated ones
…O topics

- A resource re-created in place of an existing one (types without an
  in-place update, ECS task definitions) keeps the name it was
  generated, recovered from its physical id; resources named after
  their logical id by older builds keep that name too
- An UpdateReplacePolicy-retained resource frees no name, so its
  replacement generates a new one
- An unnamed FIFO topic gets the .fifo ending
…e legacy names

- Re-provisioning with UpdateReplacePolicy Retain stands in for an
  in-place update too, so an unnamed resource keeps its name there
- Names older builds gave unnamed resources (cfn-* prefixes,
  {LogicalId}-{8 hex}) are recognized and kept
…gacy names

- A replacement whose old resource UpdateReplacePolicy retains gets a
  new name instead of overwriting the retained resource
- Legacy names are recognized only in the name part of a physical id
  and only in the exact shapes older builds generated
- Trim a separator left at a truncation cut so names never carry '--'
- Recover truncated FIFO names, generated with room for .fifo
- Name limits for Route 53 and CloudFront caller references
@vieiralucas
vieiralucas merged commit 7c5796a into main Sep 15, 2026
157 checks passed
@vieiralucas
vieiralucas deleted the fix/cfn-generated-physical-names branch September 15, 2026 16:28
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.

1 participant