Repository navigation
Description
Found while bumping a downstream project from 0.88.0 to 0.90.0. Deploying the same
template twice fails on the second stack. v0.89.0's rollback is what surfaced
this — the create was already failing on 0.88.0, but the stack still reported
CREATE_COMPLETE, so the failure was invisible. This is the same
answers-200-while-wrong shape 0.88.0/0.89.0/0.90.0 have been closing, one layer
down: in the physical name allocator rather than in a handler.
Reproducer
12-line template, no properties beyond the required one:
import boto3
TPL = """AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: {Service: ecs-tasks.amazonaws.com}
Action: sts:AssumeRole
"""
c = boto3.client("cloudformation", endpoint_url="http://localhost:4566",
region_name="us-east-1", aws_access_key_id="t", aws_secret_access_key="t")
i = boto3.client("iam", endpoint_url="http://localhost:4566",
region_name="us-east-1", aws_access_key_id="t", aws_secret_access_key="t")
for n in ("repro-a", "repro-b"):
c.create_stack(StackName=n, TemplateBody=TPL,
Capabilities=["CAPABILITY_IAM"], DisableRollback=True)
s = c.describe_stacks(StackName=n)["Stacks"][0]
print(f"{n}: {s['StackStatus']} {s.get('StackStatusReason','')}")
print("role names:", [r["RoleName"] for r in i.list_roles()["Roles"]])Against a freshly reset ghcr.io/scttfrdmn/substrate:0.90.0:
repro-a: CREATE_COMPLETE
repro-b: CREATE_FAILED MyRole (AWS::IAM::Role): EntityAlreadyExists: Role with name MyRole already exists.
role names: ['MyRole']
Expected
The template sets no RoleName. When a physical name is omitted,
CloudFormation generates one that is unique per stack, conventionally
{stack-name}-{logical-id}-{random suffix} — so repro-a and repro-b would
hold two distinct roles and both stacks would reach CREATE_COMPLETE:
role names: ['repro-a-MyRole-1QBZ8XK7YN4M2', 'repro-b-MyRole-A9F3PWL0VC6RT']
Substrate instead uses the logical ID verbatim as the physical name. A logical
ID is only unique within a stack, while an IAM role name is account-global, so any
second stack from the same template necessarily collides.
Why it matters beyond the error
Omitting the physical name is the recommended practice, not an edge case — it
is what makes a template deployable more than once, and AWS documents that
supplying an explicit name costs you replacement updates. So the templates most
likely to be written correctly are the ones that cannot deploy twice here.
The blast radius is wider than IAM. Every AWS::* type whose name is
account-unique and auto-generated when omitted has the same exposure — log groups,
ECS clusters, S3 buckets, SQS queues, Lambda functions. IAM is just where I hit it
first.
It also interacts with #518's delete sweep: a per-stack generated name is what
makes teardown of two concurrent stacks separable. With logical IDs as physical
names, deleting either stack targets the same underlying resource.
Downstream impact
In parsl-ephemeral-provider this took 6 integration tests from passing to
failing on the 0.90.0 bump — bastion.yml (BastionHostRole) and
ecs_worker.yml (TaskRole, TaskExecutionRole). Neither template sets a
name, both deploy repeatedly in one account against real AWS. I have reverted the
pin to 0.88.0 for now; happy to re-verify against a build once this lands.
Two notes from the diagnosis, in case they are useful:
DescribeStackEventsreturnsUnsupportedOperation("substrate models stack
status, not per-resource stack events"), so the failing resource is not
reachable that way.DisableRollback=TrueplusDescribeStackResourcesis what
exposed it — a nice consequence of CloudFormation: a failed resource does not roll the stack back #520.- The
StackStatusReasonon aCREATE_FAILEDstack aggregates every failed
resource with its error, which made this quick to pin down. That part is good.
Activity
scttfrdmn commentedon Aug 6, 2026
Three measurements on
main(97718ff, latest tagv0.93.0) before implementing. Two of them change the fix as filed.1. Reproduces exactly as written.
repro-a→CREATE_COMPLETE;repro-b→CREATE_FAILED,MyRole (AWS::IAM::Role): EntityAlreadyExists;list-roles→['MyRole'].2. There is a second, worse failure mode this issue does not name — silent sharing. A 7-type probe stack deployed twice hard-failed on five types (
RoleEntityAlreadyExists,BucketBucketAlreadyExists,LogGroupResourceAlreadyExistsException,TableResourceInUseException,InstanceProfileEntityAlreadyExists) — butSQS::QueueandSNS::Topicboth reportedCREATE_COMPLETE, because their creates are idempotent. The two stacks then point at one resource. Deleting the second stack destroyed the first stack's queue (QueueDoesNotExist) while the first stack still reportedCREATE_COMPLETE. So for those types the failure is not a refusal a caller can see — it is cross-stack data loss with no error reported to anyone. The fix needs a gate for this, not only for the collision.3. The suffix must be derived, not random. This issue's expected output shows random suffixes (
repro-a-MyRole-1QBZ8XK7YN4M2), and that would breakUpdateStack.UpdateStackin substrate is a re-Deployof the whole template —clearUnchangedRedeploys(emulator/cfn_rollback.go:195) exists precisely because every unchanged resource is created again. Measured: anupdate-stackon an unchanged template givesUPDATE_COMPLETEand everyPhysicalResourceIdstays put. A name regenerated per deploy would mint a new resource on every update and leak the old one.So the name will be
{stack}-{logicalID}-{suffix}with the suffix derived:FNV-64a(accountID/region/stackName/logicalID)in base36. That keeps every property asked for here — unique per stack, opaque, the documented shape — and adds the one substrate needs: stability across updates. Account and Region are in the hash because two same-named stacks in different Regions are different stacks, whichsameScopealready treats as such. This is a deliberate divergence from AWS (which randomises) and the release notes will say so under Provenance.One scoping note. The 68
resolveStringProp(..., logicalID, ...)fallbacks are not 68 name bugs, so the fix is a table of resource types, not a blanket rewrite. Only properties that are account- or Region-unique names qualify.PathPart(an API Gateway URL segment),Domain,SecretId,ClusterIdandReplicationGroupIdare deliberately excluded — they are identifiers a template legitimately controls, and generating them would change URL paths. A type absent from the table keeps today's behaviour.Format and charset provenance: the CFN resource custom naming reference (
MyStack-MyBucket-abcdefghijk1; must begin with a letter, ASCII letters/digits/hyphens only, no trailing or doubled hyphen). Truncation is mandatory rather than optional: a 40-char stack plus a 40-char logical ID is 94 characters against S3's 63-char limit, and substrate validates bucket names but not IAM role-name length, so an untruncated name would fail for some types and not others.Milestoned into v0.94.0.
fix(cfn): generate a per-stack physical name when a template omits one (