@@ -61,13 +61,13 @@ export function fullDiff(
6161 normalize ( newTemplate ) ;
6262 const theDiff = diffTemplate ( currentTemplate , newTemplate ) ;
6363 if ( changeSet ) {
64- filterFalsePositivies ( theDiff , changeSet ) ;
64+ filterFalsePositivies ( theDiff , findResourceReplacements ( changeSet ) ) ;
6565 }
6666
6767 return theDiff ;
6868}
6969
70- function diffTemplate (
70+ export function diffTemplate (
7171 currentTemplate : { [ key : string ] : any } ,
7272 newTemplate : { [ key : string ] : any } ,
7373) : types . TemplateDiff {
@@ -217,8 +217,7 @@ function deepCopy(x: any): any {
217217 return x ;
218218}
219219
220- function filterFalsePositivies ( diff : types . TemplateDiff , changeSet : CloudFormation . DescribeChangeSetOutput | NestedChangeSet ) {
221- const replacements = findResourceReplacements ( changeSet ) ;
220+ function filterFalsePositivies ( diff : types . TemplateDiff , replacements : types . ResourceReplacements ) {
222221 diff . resources . forEachDifference ( ( logicalId : string , change : types . ResourceDifference ) => {
223222 change . forEachDifference ( ( type : 'Property' | 'Other' , name : string , value : types . Difference < any > | types . PropertyDifference < any > ) => {
224223 if ( type === 'Property' ) {
@@ -227,6 +226,16 @@ function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormati
227226 ( value as types . PropertyDifference < any > ) . isDifferent = false ;
228227 return ;
229228 }
229+ // to make this work, diff needs to be aware that there can be nested templates. Currently, we don't really have this.
230+
231+ /*
232+ if (name === 'NestedTemplate') {
233+ (value as types.PropertyDifference<any>).changeImpact = types.ResourceImpact.WILL_UPDATE;
234+ filterFalsePositivies(diff, replacements[logicalId].nestedReplacements!);
235+ return;
236+ }
237+ */
238+
230239 switch ( replacements [ logicalId ] . propertiesReplaced [ name ] ) {
231240 case 'Always' :
232241 ( value as types . PropertyDifference < any > ) . changeImpact = types . ResourceImpact . WILL_REPLACE ;
@@ -243,6 +252,12 @@ function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormati
243252 break ;
244253 // otherwise, defer to the changeImpact from `diffTemplate`
245254 }
255+
256+ /*
257+ if (replacements[logicalId].nestedReplacements) {
258+ filterFalsePositivies(diff, replacements[logicalId].nestedReplacements!);
259+ }
260+ */
246261 } else if ( type === 'Other' ) {
247262 switch ( name ) {
248263 case 'Metadata' :
@@ -254,14 +269,15 @@ function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormati
254269 } ) ;
255270}
256271
257- function findResourceReplacements ( changeSet : NestedChangeSet , replacements : types . ResourceReplacements = { } ) : types . ResourceReplacements {
258- for ( const resourceChange of changeSet . Changes ?? [ ] ) {
272+ function findResourceReplacements ( changeSet : NestedChangeSet ) : types . ResourceReplacements {
273+ const replacements : types . ResourceReplacements = { } ;
274+ for ( const change of changeSet . Changes ?? [ ] ) {
259275 const propertiesReplaced : { [ propName : string ] : types . ChangeSetReplacement } = { } ;
260- if ( resourceChange . ResourceChange ?. NestedChanges ) {
261- // eslint-disable-next-line max-len
262- findResourceReplacements ( resourceChange . ResourceChange . NestedChanges , replacements [ resourceChange . ResourceChange ! . LogicalResourceId ! ] as types . ResourceReplacements ) ;
276+ const resourceChange = change . ResourceChange ;
277+ if ( ! resourceChange ) {
278+ continue ;
263279 }
264- for ( const propertyChange of resourceChange . ResourceChange ?. Details ?? [ ] ) {
280+ for ( const propertyChange of resourceChange . Details ?? [ ] ) {
265281 if ( propertyChange . Target ?. Attribute === 'Properties' ) {
266282 const requiresReplacement = propertyChange . Target . RequiresRecreation === 'Always' ;
267283 if ( requiresReplacement && propertyChange . Evaluation === 'Static' ) {
@@ -275,9 +291,10 @@ function findResourceReplacements(changeSet: NestedChangeSet, replacements: type
275291 }
276292 }
277293 }
278- replacements [ resourceChange . ResourceChange ?. LogicalResourceId ! ] = {
279- resourceReplaced : resourceChange . ResourceChange ?. Replacement === 'True' ,
294+ replacements [ resourceChange . LogicalResourceId ! ] = {
295+ resourceReplaced : resourceChange . Replacement === 'True' ,
280296 propertiesReplaced,
297+ nestedReplacements : resourceChange . NestedChanges ? findResourceReplacements ( resourceChange . NestedChanges ) : undefined ,
281298 } ;
282299 }
283300
0 commit comments