Skip to content

Commit

Permalink
reset point, in case I break it all...
Browse files Browse the repository at this point in the history
  • Loading branch information
comcalvi committed Jan 8, 2024
1 parent c2fe021 commit d89866d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
17 changes: 14 additions & 3 deletions packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export * from './diff/types';
type DiffHandler = (diff: types.ITemplateDiff, oldValue: any, newValue: any) => void;
type HandlerRegistry = { [section: string]: DiffHandler };

export type NestedChangeSet = CloudFormation.DescribeChangeSetOutput & {
Changes?: CloudFormation.Changes & {
ResourceChange?: {
NestedChanges?: CloudFormation.DescribeChangeSetOutput | NestedChangeSet,
},
}[],
};

const DIFF_HANDLERS: HandlerRegistry = {
AWSTemplateFormatVersion: (diff, oldValue, newValue) =>
diff.awsTemplateFormatVersion = impl.diffAttribute(oldValue, newValue),
Expand Down Expand Up @@ -209,7 +217,7 @@ function deepCopy(x: any): any {
return x;
}

function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormation.DescribeChangeSetOutput) {
function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormation.DescribeChangeSetOutput | NestedChangeSet) {
const replacements = findResourceReplacements(changeSet);
diff.resources.forEachDifference((logicalId: string, change: types.ResourceDifference) => {
change.forEachDifference((type: 'Property' | 'Other', name: string, value: types.Difference<any> | types.PropertyDifference<any>) => {
Expand Down Expand Up @@ -246,10 +254,13 @@ function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormati
});
}

function findResourceReplacements(changeSet: CloudFormation.DescribeChangeSetOutput): types.ResourceReplacements {
const replacements: types.ResourceReplacements = {};
function findResourceReplacements(changeSet: NestedChangeSet, replacements: types.ResourceReplacements = {}): types.ResourceReplacements {
for (const resourceChange of changeSet.Changes ?? []) {
const propertiesReplaced: { [propName: string]: types.ChangeSetReplacement } = {};
if (resourceChange.ResourceChange?.NestedChanges) {
// eslint-disable-next-line max-len
findResourceReplacements(resourceChange.ResourceChange.NestedChanges, replacements[resourceChange.ResourceChange!.LogicalResourceId!] as types.ResourceReplacements);
}
for (const propertyChange of resourceChange.ResourceChange?.Details ?? []) {
if (propertyChange.Target?.Attribute === 'Properties') {
const requiresReplacement = propertyChange.Target.RequiresRecreation === 'Always';
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SecurityGroupChanges } from '../network/security-group-changes';

export type PropertyMap = {[key: string]: any };

export type ResourceReplacements = { [logicalId: string]: ResourceReplacement };
export type ResourceReplacements = { [logicalId: string]: ResourceReplacement | ResourceReplacements };

export interface ResourceReplacement {
resourceReplaced: boolean,
Expand Down
9 changes: 1 addition & 8 deletions packages/aws-cdk/lib/api/nested-stack-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { NestedChangeSet } from '@aws-cdk/cloudformation-diff';
import * as cxapi from '@aws-cdk/cx-api';
import { CloudFormation } from 'aws-sdk';
import * as fs from 'fs-extra';
Expand All @@ -21,14 +22,6 @@ export interface TemplateWithNestedStackCount {
readonly nestedStackCount: number;
}

export type NestedChangeSet = CloudFormation.DescribeChangeSetOutput & {
Changes?: CloudFormation.Changes & {
ResourceChange?: {
NestedChanges?: CloudFormation.DescribeChangeSetOutput | NestedChangeSet,
},
}[],
};

/**
* Reads the currently deployed template from CloudFormation and adds a
* property, `NestedTemplate`, to any nested stacks that appear in either
Expand Down
1 change: 0 additions & 1 deletion packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export class CdkToolkit {
const templateWithNames = await this.props.deployments.readCurrentTemplateWithNestedStacks(
stack, options.compareAgainstProcessedTemplate,
);

const currentTemplate = templateWithNames.deployedTemplate;
const nestedStackCount = templateWithNames.nestedStackCount;

Expand Down

0 comments on commit d89866d

Please sign in to comment.