Skip to content

Commit

Permalink
fix: evaluate all nested stacks during GetAtt evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer committed Nov 21, 2023
1 parent 25ee8ef commit 207be27
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/aws-cdk/lib/api/evaluate-cloudformation-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class EvaluateCloudFormationTemplate {

if (foundResource.ResourceType == 'AWS::CloudFormation::Stack' && attribute?.startsWith('Outputs.')) {
// need to resolve attributes from another stack's Output section
const dependantStackName = this.nestedStackNames[logicalId]?.nestedStackPhysicalName;
const dependantStackName = this.findNestedStack(logicalId, this.nestedStackNames);
if (!dependantStackName) {
//this is a newly created nested stack and cannot be hotswapped
return undefined;
Expand All @@ -406,6 +406,19 @@ export class EvaluateCloudFormationTemplate {
return this.formatResourceAttribute(foundResource, attribute);
}

private findNestedStack(logicalId: string, nestedStackNames: {
[nestedStackLogicalId: string]: NestedStackNames;
}): string | undefined {
for (const [nestedStackLogicalId, { nestedChildStackNames, nestedStackPhysicalName }] of Object.entries(nestedStackNames)) {
if (nestedStackLogicalId === logicalId) {
return nestedStackPhysicalName;
}
const checkInNestedChildStacks = this.findNestedStack(logicalId, nestedChildStackNames);
if (checkInNestedChildStacks) return checkInNestedChildStacks;
}
return undefined;
}

private formatResourceAttribute(resource: AWS.CloudFormation.StackResourceSummary, attribute: string | undefined): string | undefined {
const physicalId = resource.PhysicalResourceId;

Expand Down

0 comments on commit 207be27

Please sign in to comment.