Skip to content

Commit

Permalink
nice work
Browse files Browse the repository at this point in the history
  • Loading branch information
bergjaak committed May 7, 2024
1 parent 2c53cf9 commit 9878273
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
35 changes: 33 additions & 2 deletions packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function fullDiff(
normalize(newTemplate);
const theDiff = diffTemplate(currentTemplate, newTemplate);
if (changeSet) {
filterFalsePositives(theDiff, changeSet);
filterFalsePositives(theDiff, changeSet, newTemplate.Resources);
addImportInformation(theDiff, changeSet);
} else if (isImport) {
makeAllResourceChangesImports(theDiff);
Expand Down Expand Up @@ -229,8 +229,39 @@ function makeAllResourceChangesImports(diff: types.TemplateDiff) {
});
}

function filterFalsePositives(diff: types.TemplateDiff, changeSet: DescribeChangeSetOutput) {
function filterFalsePositives(diff: types.TemplateDiff, changeSet: DescribeChangeSetOutput, newTemplateResources: {[logicalId: string]: any}) {
const replacements = findResourceReplacements(changeSet);

for (const logicalId of Object.keys(newTemplateResources || {})) {
if (logicalId in replacements) {
// diff.resources.get(logicalId).isDifferent = true;
// Then the properties that have been replaced need to be referenced
for (const propertyName of Object.keys(replacements[logicalId].propertiesReplaced)) {

if (logicalId in diff.resources) {
// In this case, a property of a changed resource may have been skipped
if (!(propertyName in diff.resources.get(logicalId).propertyUpdates)) {
const newProp = new types.PropertyDifference(
// these fields we be decided below
{}, {}, { changeImpact: undefined },
);
newProp.isDifferent = true;
diff.resources.get(logicalId).propertyUpdates[propertyName] = newProp;
}
} else {
// In this case, we missed the resource entirely.
diff.resources.add(logicalId, diffResource(newTemplateResources[logicalId], newTemplateResources[logicalId]));
const newProp = new types.PropertyDifference(
// these fields we be decided below
{}, {}, { changeImpact: undefined },
);
newProp.isDifferent = true;
diff.resources.get(logicalId).setPropertyChange(propertyName, newProp);
}
}
}
};

diff.resources.forEachDifference((logicalId: string, change: types.ResourceDifference) => {
if (change.resourceType.includes('AWS::Serverless')) {
// CFN applies the SAM transform before creating the changeset, so the changeset contains no information about SAM resources
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ export class PropertyDifference<ValueType> extends Difference<ValueType> {
export class DifferenceCollection<V, T extends IDifference<V>> {
constructor(private readonly diffs: { [logicalId: string]: T }) {}

public add(logicalId: string, diff: T): void {
this.diffs[logicalId] = diff;
}

public get changes(): { [logicalId: string]: T } {
return onlyChanges(this.diffs);
}
Expand Down

0 comments on commit 9878273

Please sign in to comment.