(core): PhysicalNames and Nested Stacks
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When the physicalName is generated (`Resource` `generatePhysicalName()`) for a resource inside a `cdk.NestedStack`, the name generated is incorrect as it contains the stack "Token identifier" instead of the substituted value.
### Expected Behavior
The pyshicalName is generated correctly
### Current Behavior
The physical name looks something like this: `"${token[token.399]}estacknestedtest2ad16ad137c06fec44b9"`.
### Reproduction Steps
Create something like the following
```
const app = new cdk.App();
const stack1 = new ServiceStack(app, "ServiceStack", {
env: {
account: '111111',
region: 'us-east-1'
}
});
new ServiceStack(app, "ServiceStack2", {
env: {
account: '111111',
region: 'eu-west-1'
}
refBucket: stack1.nestedBucket,
});
export type ServiceStackProps = cdk.StackProps & {
refBucket?: s3.IBucket;
};
export class ServiceStack extends cdk.Stack {
public nestedBucket: s3.IBucket;
constructor(scope: Construct, id: string, props: ServiceStackProps) {
super(scope, id, props);
const nested = new ServiceNested(this, "Nested", {});
this.nestedBucket = nested.nestedBucket;
props.refBucket &&
new cdk.CfnOutput(this, "OutRef", {
value: props.refBucket.bucketName,
});
}
}
export class ServiceNested extends cdk.NestedStack {
public nestedBucket: s3.IBucket;
constructor(scope: Construct, id: string, props: cdk.NestedStackProps) {
super(scope, id, props);
this.nestedBucket = new s3.Bucket(this, "Test", {
bucketName: cdk.PhysicalName.GENERATE_IF_NEEDED,
});
}
}
```
You will see in the synth output:
```
"Outputs": {
"OutRef": {
"Value": "${token[token.399]}estacknestedtest2ad16ad137c06fec44b9"
}
},
```
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.19
### Framework Version
2.19
### Node.js Version
16.14
### OS
Ubuntu 20
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.