@aws-cdk/cloudformation-diff 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +12 -0
  4. package/lib/diff/index.d.ts +9 -0
  5. package/lib/diff/index.js +92 -0
  6. package/lib/diff/maybe-parsed.d.ts +14 -0
  7. package/lib/diff/maybe-parsed.js +14 -0
  8. package/lib/diff/template-and-changeset-diff-merger.d.ts +33 -0
  9. package/lib/diff/template-and-changeset-diff-merger.js +128 -0
  10. package/lib/diff/types.d.ts +368 -0
  11. package/lib/diff/types.js +498 -0
  12. package/lib/diff/util.d.ts +57 -0
  13. package/lib/diff/util.js +199 -0
  14. package/lib/diff-template.d.ts +25 -0
  15. package/lib/diff-template.js +212 -0
  16. package/lib/diffable.d.ts +22 -0
  17. package/lib/diffable.js +47 -0
  18. package/lib/format-table.d.ts +6 -0
  19. package/lib/format-table.js +108 -0
  20. package/lib/format.d.ts +106 -0
  21. package/lib/format.js +436 -0
  22. package/lib/iam/iam-changes.d.ts +66 -0
  23. package/lib/iam/iam-changes.js +421 -0
  24. package/lib/iam/iam-identity-center.d.ts +78 -0
  25. package/lib/iam/iam-identity-center.js +46 -0
  26. package/lib/iam/managed-policy.d.ts +11 -0
  27. package/lib/iam/managed-policy.js +33 -0
  28. package/lib/iam/statement.d.ts +113 -0
  29. package/lib/iam/statement.js +270 -0
  30. package/lib/index.d.ts +4 -0
  31. package/lib/index.js +24 -0
  32. package/lib/network/security-group-changes.d.ts +32 -0
  33. package/lib/network/security-group-changes.js +99 -0
  34. package/lib/network/security-group-rule.d.ts +50 -0
  35. package/lib/network/security-group-rule.js +97 -0
  36. package/lib/render-intrinsics.d.ts +21 -0
  37. package/lib/render-intrinsics.js +78 -0
  38. package/lib/util.d.ts +7 -0
  39. package/lib/util.js +62 -0
  40. package/package.json +80 -0
@@ -0,0 +1,368 @@
1
+ import { PropertyScrutinyType, ResourceScrutinyType } from '@aws-cdk/service-spec-types';
2
+ import { IamChanges } from '../iam/iam-changes';
3
+ import { SecurityGroupChanges } from '../network/security-group-changes';
4
+ export type PropertyMap = {
5
+ [key: string]: any;
6
+ };
7
+ export type ChangeSetResources = {
8
+ [logicalId: string]: ChangeSetResource;
9
+ };
10
+ /**
11
+ * @param beforeContext is the BeforeContext field from the ChangeSet.ResourceChange.BeforeContext. This is the part of the CloudFormation template
12
+ * that defines what the resource is before the change is applied; that is, BeforeContext is CloudFormationTemplate.Resources[LogicalId] before the ChangeSet is executed.
13
+ *
14
+ * @param afterContext same as beforeContext but for after the change is made; that is, AfterContext is CloudFormationTemplate.Resources[LogicalId] after the ChangeSet is executed.
15
+ *
16
+ * * Here is an example of what a beforeContext/afterContext looks like:
17
+ * '{"Properties":{"Value":"sdflkja","Type":"String","Name":"mySsmParameterFromStack"},"Metadata":{"aws:cdk:path":"cdk/mySsmParameter/Resource"}}'
18
+ */
19
+ export interface ChangeSetResource {
20
+ resourceWasReplaced: boolean;
21
+ resourceType: string | undefined;
22
+ propertyReplacementModes: PropertyReplacementModeMap | undefined;
23
+ }
24
+ export type PropertyReplacementModeMap = {
25
+ [propertyName: string]: {
26
+ replacementMode: ReplacementModes | undefined;
27
+ };
28
+ };
29
+ /**
30
+ * 'Always' means that changing the corresponding property will always cause a resource replacement. Never means never. Conditionally means maybe.
31
+ */
32
+ export type ReplacementModes = 'Always' | 'Never' | 'Conditionally';
33
+ /** Semantic differences between two CloudFormation templates. */
34
+ export declare class TemplateDiff implements ITemplateDiff {
35
+ awsTemplateFormatVersion?: Difference<string>;
36
+ description?: Difference<string>;
37
+ transform?: Difference<string>;
38
+ conditions: DifferenceCollection<Condition, ConditionDifference>;
39
+ mappings: DifferenceCollection<Mapping, MappingDifference>;
40
+ metadata: DifferenceCollection<Metadata, MetadataDifference>;
41
+ outputs: DifferenceCollection<Output, OutputDifference>;
42
+ parameters: DifferenceCollection<Parameter, ParameterDifference>;
43
+ resources: DifferenceCollection<Resource, ResourceDifference>;
44
+ /** The differences in unknown/unexpected parts of the template */
45
+ unknown: DifferenceCollection<any, Difference<any>>;
46
+ /**
47
+ * Changes to IAM policies
48
+ */
49
+ readonly iamChanges: IamChanges;
50
+ /**
51
+ * Changes to Security Group ingress and egress rules
52
+ */
53
+ readonly securityGroupChanges: SecurityGroupChanges;
54
+ constructor(args: ITemplateDiff);
55
+ get differenceCount(): number;
56
+ get isEmpty(): boolean;
57
+ /**
58
+ * Return true if any of the permissions objects involve a broadening of permissions
59
+ */
60
+ get permissionsBroadened(): boolean;
61
+ /**
62
+ * Return true if any of the permissions objects have changed
63
+ */
64
+ get permissionsAnyChanges(): boolean;
65
+ /**
66
+ * Return all property changes of a given scrutiny type
67
+ *
68
+ * We don't just look at property updates; we also look at resource additions and deletions (in which
69
+ * case there is no further detail on property values), and resource type changes.
70
+ */
71
+ private scrutinizablePropertyChanges;
72
+ /**
73
+ * Return all resource changes of a given scrutiny type
74
+ *
75
+ * We don't just look at resource updates; we also look at resource additions and deletions (in which
76
+ * case there is no further detail on property values), and resource type changes.
77
+ */
78
+ private scrutinizableResourceChanges;
79
+ private resourceIsScrutinizable;
80
+ }
81
+ /**
82
+ * A change in property values
83
+ *
84
+ * Not necessarily an update, it could be that there used to be no value there
85
+ * because there was no resource, and now there is (or vice versa).
86
+ *
87
+ * Therefore, we just contain plain values and not a PropertyDifference<any>.
88
+ */
89
+ export interface PropertyChange {
90
+ /**
91
+ * Logical ID of the resource where this property change was found
92
+ */
93
+ resourceLogicalId: string;
94
+ /**
95
+ * Type of the resource
96
+ */
97
+ resourceType: string;
98
+ /**
99
+ * Scrutiny type for this property change
100
+ */
101
+ scrutinyType: PropertyScrutinyType;
102
+ /**
103
+ * Name of the property that is changing
104
+ */
105
+ propertyName: string;
106
+ /**
107
+ * The old property value
108
+ */
109
+ oldValue?: any;
110
+ /**
111
+ * The new property value
112
+ */
113
+ newValue?: any;
114
+ }
115
+ /**
116
+ * A resource change
117
+ *
118
+ * Either a creation, deletion or update.
119
+ */
120
+ export interface ResourceChange {
121
+ /**
122
+ * Logical ID of the resource where this property change was found
123
+ */
124
+ resourceLogicalId: string;
125
+ /**
126
+ * Scrutiny type for this resource change
127
+ */
128
+ scrutinyType: ResourceScrutinyType;
129
+ /**
130
+ * The type of the resource
131
+ */
132
+ resourceType: string;
133
+ /**
134
+ * The old properties value (might be undefined in case of creation)
135
+ */
136
+ oldProperties?: PropertyMap;
137
+ /**
138
+ * The new properties value (might be undefined in case of deletion)
139
+ */
140
+ newProperties?: PropertyMap;
141
+ }
142
+ export interface IDifference<ValueType> {
143
+ readonly oldValue: ValueType | undefined;
144
+ readonly newValue: ValueType | undefined;
145
+ readonly isDifferent: boolean;
146
+ readonly isAddition: boolean;
147
+ readonly isRemoval: boolean;
148
+ readonly isUpdate: boolean;
149
+ }
150
+ /**
151
+ * Models an entity that changed between two versions of a CloudFormation template.
152
+ */
153
+ export declare class Difference<ValueType> implements IDifference<ValueType> {
154
+ readonly oldValue: ValueType | undefined;
155
+ readonly newValue: ValueType | undefined;
156
+ /**
157
+ * Whether this is an actual different or the values are actually the same
158
+ *
159
+ * isDifferent => (isUpdate | isRemoved | isUpdate)
160
+ */
161
+ isDifferent: boolean;
162
+ /**
163
+ * @param oldValue the old value, cannot be equal (to the sense of +deepEqual+) to +newValue+.
164
+ * @param newValue the new value, cannot be equal (to the sense of +deepEqual+) to +oldValue+.
165
+ */
166
+ constructor(oldValue: ValueType | undefined, newValue: ValueType | undefined);
167
+ /** @returns +true+ if the element is new to the template. */
168
+ get isAddition(): boolean;
169
+ /** @returns +true+ if the element was removed from the template. */
170
+ get isRemoval(): boolean;
171
+ /** @returns +true+ if the element was already in the template and is updated. */
172
+ get isUpdate(): boolean;
173
+ }
174
+ export declare class PropertyDifference<ValueType> extends Difference<ValueType> {
175
+ changeImpact?: ResourceImpact;
176
+ constructor(oldValue: ValueType | undefined, newValue: ValueType | undefined, args: {
177
+ changeImpact?: ResourceImpact;
178
+ });
179
+ }
180
+ export declare class DifferenceCollection<V, T extends IDifference<V>> {
181
+ private readonly diffs;
182
+ constructor(diffs: {
183
+ [logicalId: string]: T;
184
+ });
185
+ get changes(): {
186
+ [logicalId: string]: T;
187
+ };
188
+ get differenceCount(): number;
189
+ get(logicalId: string): T;
190
+ remove(logicalId: string): void;
191
+ get logicalIds(): string[];
192
+ /**
193
+ * Returns a new TemplateDiff which only contains changes for which `predicate`
194
+ * returns `true`.
195
+ */
196
+ filter(predicate: (diff: T | undefined) => boolean): DifferenceCollection<V, T>;
197
+ /**
198
+ * Invokes `cb` for all changes in this collection.
199
+ *
200
+ * Changes will be sorted as follows:
201
+ * - Removed
202
+ * - Added
203
+ * - Updated
204
+ * - Others
205
+ *
206
+ */
207
+ forEachDifference(cb: (logicalId: string, change: T) => any): void;
208
+ }
209
+ /**
210
+ * Arguments expected by the constructor of +TemplateDiff+, extracted as an interface for the sake
211
+ * of (relative) conciseness of the constructor's signature.
212
+ */
213
+ export interface ITemplateDiff {
214
+ awsTemplateFormatVersion?: IDifference<string>;
215
+ description?: IDifference<string>;
216
+ transform?: IDifference<string>;
217
+ conditions?: DifferenceCollection<Condition, ConditionDifference>;
218
+ mappings?: DifferenceCollection<Mapping, MappingDifference>;
219
+ metadata?: DifferenceCollection<Metadata, MetadataDifference>;
220
+ outputs?: DifferenceCollection<Output, OutputDifference>;
221
+ parameters?: DifferenceCollection<Parameter, ParameterDifference>;
222
+ resources?: DifferenceCollection<Resource, ResourceDifference>;
223
+ unknown?: DifferenceCollection<any, IDifference<any>>;
224
+ }
225
+ export type Condition = any;
226
+ export declare class ConditionDifference extends Difference<Condition> {
227
+ }
228
+ export type Mapping = any;
229
+ export declare class MappingDifference extends Difference<Mapping> {
230
+ }
231
+ export type Metadata = any;
232
+ export declare class MetadataDifference extends Difference<Metadata> {
233
+ }
234
+ export type Output = any;
235
+ export declare class OutputDifference extends Difference<Output> {
236
+ }
237
+ export type Parameter = any;
238
+ export declare class ParameterDifference extends Difference<Parameter> {
239
+ }
240
+ export declare enum ResourceImpact {
241
+ /** The existing physical resource will be updated */
242
+ WILL_UPDATE = "WILL_UPDATE",
243
+ /** A new physical resource will be created */
244
+ WILL_CREATE = "WILL_CREATE",
245
+ /** The existing physical resource will be replaced */
246
+ WILL_REPLACE = "WILL_REPLACE",
247
+ /** The existing physical resource may be replaced */
248
+ MAY_REPLACE = "MAY_REPLACE",
249
+ /** The existing physical resource will be destroyed */
250
+ WILL_DESTROY = "WILL_DESTROY",
251
+ /** The existing physical resource will be removed from CloudFormation supervision */
252
+ WILL_ORPHAN = "WILL_ORPHAN",
253
+ /** The existing physical resource will be added to CloudFormation supervision */
254
+ WILL_IMPORT = "WILL_IMPORT",
255
+ /** There is no change in this resource */
256
+ NO_CHANGE = "NO_CHANGE"
257
+ }
258
+ export interface Resource {
259
+ Type: string;
260
+ Properties?: {
261
+ [name: string]: any;
262
+ };
263
+ [key: string]: any;
264
+ }
265
+ /**
266
+ * Change to a single resource between two CloudFormation templates
267
+ *
268
+ * This class can be mutated after construction.
269
+ */
270
+ export declare class ResourceDifference implements IDifference<Resource> {
271
+ readonly oldValue: Resource | undefined;
272
+ readonly newValue: Resource | undefined;
273
+ /**
274
+ * Whether this resource was added
275
+ */
276
+ readonly isAddition: boolean;
277
+ /**
278
+ * Whether this resource was removed
279
+ */
280
+ readonly isRemoval: boolean;
281
+ /**
282
+ * Whether this resource was imported
283
+ */
284
+ isImport?: boolean;
285
+ /** Property-level changes on the resource */
286
+ private readonly propertyDiffs;
287
+ /** Changes to non-property level attributes of the resource */
288
+ private readonly otherDiffs;
289
+ /** The resource type (or old and new type if it has changed) */
290
+ private readonly resourceTypes;
291
+ constructor(oldValue: Resource | undefined, newValue: Resource | undefined, args: {
292
+ resourceType: {
293
+ oldType?: string;
294
+ newType?: string;
295
+ };
296
+ propertyDiffs: {
297
+ [key: string]: PropertyDifference<any>;
298
+ };
299
+ otherDiffs: {
300
+ [key: string]: Difference<any>;
301
+ };
302
+ });
303
+ get oldProperties(): PropertyMap | undefined;
304
+ get newProperties(): PropertyMap | undefined;
305
+ /**
306
+ * Whether this resource was modified at all
307
+ */
308
+ get isDifferent(): boolean;
309
+ /**
310
+ * Whether the resource was updated in-place
311
+ */
312
+ get isUpdate(): boolean;
313
+ get oldResourceType(): string | undefined;
314
+ get newResourceType(): string | undefined;
315
+ /**
316
+ * All actual property updates
317
+ */
318
+ get propertyUpdates(): {
319
+ [key: string]: PropertyDifference<any>;
320
+ };
321
+ /**
322
+ * All actual "other" updates
323
+ */
324
+ get otherChanges(): {
325
+ [key: string]: Difference<any>;
326
+ };
327
+ /**
328
+ * Return whether the resource type was changed in this diff
329
+ *
330
+ * This is not a valid operation in CloudFormation but to be defensive we're going
331
+ * to be aware of it anyway.
332
+ */
333
+ get resourceTypeChanged(): boolean;
334
+ /**
335
+ * Return the resource type if it was unchanged
336
+ *
337
+ * If the resource type was changed, it's an error to call this.
338
+ */
339
+ get resourceType(): string | undefined;
340
+ /**
341
+ * Replace a PropertyChange in this object
342
+ *
343
+ * This affects the property diff as it is summarized to users, but it DOES
344
+ * NOT affect either the "oldValue" or "newValue" values; those still contain
345
+ * the actual template values as provided by the user (they might still be
346
+ * used for downstream processing).
347
+ */
348
+ setPropertyChange(propertyName: string, change: PropertyDifference<any>): void;
349
+ /**
350
+ * Replace a OtherChange in this object
351
+ *
352
+ * This affects the property diff as it is summarized to users, but it DOES
353
+ * NOT affect either the "oldValue" or "newValue" values; those still contain
354
+ * the actual template values as provided by the user (they might still be
355
+ * used for downstream processing).
356
+ */
357
+ setOtherChange(otherName: string, change: PropertyDifference<any>): void;
358
+ get changeImpact(): ResourceImpact;
359
+ /**
360
+ * Count of actual differences (not of elements)
361
+ */
362
+ get differenceCount(): number;
363
+ /**
364
+ * Invoke a callback for each actual difference
365
+ */
366
+ forEachDifference(cb: (type: 'Property' | 'Other', name: string, value: Difference<any> | PropertyDifference<any>) => any): void;
367
+ }
368
+ export declare function isPropertyDifference<T>(diff: Difference<T>): diff is PropertyDifference<T>;