Skip to content

Commit 9bf63ed

Browse files
authored
fix(cli): diff doesn't display paths for removed resources (#25294)
Even if the old template has paths in it, they are not displayed because all paths are loaded from the assembly metadata. Include the logicalID paths from the old template, if present, but give preference to the new template. This will show paths for removed resources, if there are any. Useful to debug replacements. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0591817 commit 9bf63ed

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/aws-cdk/lib/diff.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function printStackDiff(
3434
}
3535

3636
if (!diff.isEmpty) {
37-
cfnDiff.formatDifferences(stream || process.stderr, diff, buildLogicalToPathMap(newTemplate), context);
37+
cfnDiff.formatDifferences(stream || process.stderr, diff, {
38+
...logicalIdMapFromTemplate(oldTemplate),
39+
...buildLogicalToPathMap(newTemplate),
40+
}, context);
3841
} else {
3942
print(chalk.green('There were no differences'));
4043
}
@@ -91,3 +94,15 @@ function buildLogicalToPathMap(stack: cxapi.CloudFormationStackArtifact) {
9194
}
9295
return map;
9396
}
97+
98+
function logicalIdMapFromTemplate(template: any) {
99+
const ret: Record<string, string> = {};
100+
101+
for (const [logicalId, resource] of Object.entries(template.Resources ?? {})) {
102+
const path = (resource as any)?.Metadata?.['aws:cdk:path'];
103+
if (path) {
104+
ret[logicalId] = path;
105+
}
106+
}
107+
return ret;
108+
}

0 commit comments

Comments
 (0)