1
1
import { AssertionError } from 'assert' ;
2
- import * as cfnspec from '@aws-cdk/cfnspec ' ;
3
- import { deepEqual } from './util' ;
2
+ import { PropertyScrutinyType , ResourceScrutinyType , Resource as ResourceModel } from '@aws-cdk/service-spec-types ' ;
3
+ import { deepEqual , loadResourceModel } from './util' ;
4
4
import { IamChanges } from '../iam/iam-changes' ;
5
5
import { SecurityGroupChanges } from '../network/security-group-changes' ;
6
6
@@ -55,10 +55,10 @@ export class TemplateDiff implements ITemplateDiff {
55
55
} ) ;
56
56
57
57
this . securityGroupChanges = new SecurityGroupChanges ( {
58
- egressRulePropertyChanges : this . scrutinizablePropertyChanges ( [ cfnspec . schema . PropertyScrutinyType . EgressRules ] ) ,
59
- ingressRulePropertyChanges : this . scrutinizablePropertyChanges ( [ cfnspec . schema . PropertyScrutinyType . IngressRules ] ) ,
60
- egressRuleResourceChanges : this . scrutinizableResourceChanges ( [ cfnspec . schema . ResourceScrutinyType . EgressRuleResource ] ) ,
61
- ingressRuleResourceChanges : this . scrutinizableResourceChanges ( [ cfnspec . schema . ResourceScrutinyType . IngressRuleResource ] ) ,
58
+ egressRulePropertyChanges : this . scrutinizablePropertyChanges ( [ PropertyScrutinyType . EgressRules ] ) ,
59
+ ingressRulePropertyChanges : this . scrutinizablePropertyChanges ( [ PropertyScrutinyType . IngressRules ] ) ,
60
+ egressRuleResourceChanges : this . scrutinizableResourceChanges ( [ ResourceScrutinyType . EgressRuleResource ] ) ,
61
+ ingressRuleResourceChanges : this . scrutinizableResourceChanges ( [ ResourceScrutinyType . IngressRuleResource ] ) ,
62
62
} ) ;
63
63
}
64
64
@@ -110,7 +110,7 @@ export class TemplateDiff implements ITemplateDiff {
110
110
* We don't just look at property updates; we also look at resource additions and deletions (in which
111
111
* case there is no further detail on property values), and resource type changes.
112
112
*/
113
- private scrutinizablePropertyChanges ( scrutinyTypes : cfnspec . schema . PropertyScrutinyType [ ] ) : PropertyChange [ ] {
113
+ private scrutinizablePropertyChanges ( scrutinyTypes : PropertyScrutinyType [ ] ) : PropertyChange [ ] {
114
114
const ret = new Array < PropertyChange > ( ) ;
115
115
116
116
for ( const [ resourceLogicalId , resourceChange ] of Object . entries ( this . resources . changes ) ) {
@@ -119,16 +119,23 @@ export class TemplateDiff implements ITemplateDiff {
119
119
continue ;
120
120
}
121
121
122
- const props = cfnspec . scrutinizablePropertyNames ( resourceChange . newResourceType ! , scrutinyTypes ) ;
123
- for ( const propertyName of props ) {
124
- ret . push ( {
125
- resourceLogicalId,
126
- propertyName,
127
- resourceType : resourceChange . resourceType ,
128
- scrutinyType : cfnspec . propertySpecification ( resourceChange . resourceType , propertyName ) . ScrutinyType ! ,
129
- oldValue : resourceChange . oldProperties && resourceChange . oldProperties [ propertyName ] ,
130
- newValue : resourceChange . newProperties && resourceChange . newProperties [ propertyName ] ,
131
- } ) ;
122
+ if ( ! resourceChange . newResourceType ) {
123
+ continue ;
124
+ }
125
+
126
+ const newTypeProps = loadResourceModel ( resourceChange . newResourceType ) ?. properties || { } ;
127
+ for ( const [ propertyName , prop ] of Object . entries ( newTypeProps ) ) {
128
+ const propScrutinyType = prop . scrutinizable || PropertyScrutinyType . None ;
129
+ if ( scrutinyTypes . includes ( propScrutinyType ) ) {
130
+ ret . push ( {
131
+ resourceLogicalId,
132
+ propertyName,
133
+ resourceType : resourceChange . resourceType ,
134
+ scrutinyType : propScrutinyType ,
135
+ oldValue : resourceChange . oldProperties ?. [ propertyName ] ,
136
+ newValue : resourceChange . newProperties ?. [ propertyName ] ,
137
+ } ) ;
138
+ }
132
139
}
133
140
}
134
141
@@ -141,11 +148,9 @@ export class TemplateDiff implements ITemplateDiff {
141
148
* We don't just look at resource updates; we also look at resource additions and deletions (in which
142
149
* case there is no further detail on property values), and resource type changes.
143
150
*/
144
- private scrutinizableResourceChanges ( scrutinyTypes : cfnspec . schema . ResourceScrutinyType [ ] ) : ResourceChange [ ] {
151
+ private scrutinizableResourceChanges ( scrutinyTypes : ResourceScrutinyType [ ] ) : ResourceChange [ ] {
145
152
const ret = new Array < ResourceChange > ( ) ;
146
153
147
- const scrutinizableTypes = new Set ( cfnspec . scrutinizableResourceTypes ( scrutinyTypes ) ) ;
148
-
149
154
for ( const [ resourceLogicalId , resourceChange ] of Object . entries ( this . resources . changes ) ) {
150
155
if ( ! resourceChange ) { continue ; }
151
156
@@ -158,35 +163,47 @@ export class TemplateDiff implements ITemplateDiff {
158
163
// changes to the Type of resources can happen when migrating from CFN templates that use Transforms
159
164
if ( resourceChange . resourceTypeChanged ) {
160
165
// Treat as DELETE+ADD
161
- if ( scrutinizableTypes . has ( resourceChange . oldResourceType ! ) ) {
162
- ret . push ( {
163
- ...commonProps ,
164
- newProperties : undefined ,
165
- resourceType : resourceChange . oldResourceType ! ,
166
- scrutinyType : cfnspec . resourceSpecification ( resourceChange . oldResourceType ! ) . ScrutinyType ! ,
167
- } ) ;
166
+ if ( resourceChange . oldResourceType ) {
167
+ const oldResourceModel = loadResourceModel ( resourceChange . oldResourceType ) ;
168
+ if ( oldResourceModel && this . resourceIsScrutinizable ( oldResourceModel , scrutinyTypes ) ) {
169
+ ret . push ( {
170
+ ...commonProps ,
171
+ newProperties : undefined ,
172
+ resourceType : resourceChange . oldResourceType ! ,
173
+ scrutinyType : oldResourceModel . scrutinizable ! ,
174
+ } ) ;
175
+ }
168
176
}
169
- if ( scrutinizableTypes . has ( resourceChange . newResourceType ! ) ) {
170
- ret . push ( {
171
- ...commonProps ,
172
- oldProperties : undefined ,
173
- resourceType : resourceChange . newResourceType ! ,
174
- scrutinyType : cfnspec . resourceSpecification ( resourceChange . newResourceType ! ) . ScrutinyType ! ,
175
- } ) ;
177
+
178
+ if ( resourceChange . newResourceType ) {
179
+ const newResourceModel = loadResourceModel ( resourceChange . newResourceType ) ;
180
+ if ( newResourceModel && this . resourceIsScrutinizable ( newResourceModel , scrutinyTypes ) ) {
181
+ ret . push ( {
182
+ ...commonProps ,
183
+ oldProperties : undefined ,
184
+ resourceType : resourceChange . newResourceType ! ,
185
+ scrutinyType : newResourceModel . scrutinizable ! ,
186
+ } ) ;
187
+ }
176
188
}
177
189
} else {
178
- if ( scrutinizableTypes . has ( resourceChange . resourceType ) ) {
190
+ const resourceModel = loadResourceModel ( resourceChange . resourceType ) ;
191
+ if ( resourceModel && this . resourceIsScrutinizable ( resourceModel , scrutinyTypes ) ) {
179
192
ret . push ( {
180
193
...commonProps ,
181
194
resourceType : resourceChange . resourceType ,
182
- scrutinyType : cfnspec . resourceSpecification ( resourceChange . resourceType ) . ScrutinyType ! ,
195
+ scrutinyType : resourceModel . scrutinizable ! ,
183
196
} ) ;
184
197
}
185
198
}
186
199
}
187
200
188
201
return ret ;
189
202
}
203
+
204
+ private resourceIsScrutinizable ( res : ResourceModel , scrutinyTypes : Array < ResourceScrutinyType > ) : boolean {
205
+ return scrutinyTypes . includes ( res . scrutinizable || ResourceScrutinyType . None ) ;
206
+ }
190
207
}
191
208
192
209
/**
@@ -211,7 +228,7 @@ export interface PropertyChange {
211
228
/**
212
229
* Scrutiny type for this property change
213
230
*/
214
- scrutinyType : cfnspec . schema . PropertyScrutinyType ;
231
+ scrutinyType : PropertyScrutinyType ;
215
232
216
233
/**
217
234
* Name of the property that is changing
@@ -243,7 +260,7 @@ export interface ResourceChange {
243
260
/**
244
261
* Scrutiny type for this resource change
245
262
*/
246
- scrutinyType : cfnspec . schema . ResourceScrutinyType ;
263
+ scrutinyType : ResourceScrutinyType ;
247
264
248
265
/**
249
266
* The type of the resource
0 commit comments