Skip to content

Commit 0145866

Browse files
authored
fix: property references are skipped when DependsOn is present (refactor) (#524)
When computing the graph for the stack, if there is a `DependsOn`, the algorithm will ignore other dependencies. Also, `DependsOn` may be a string or an array, and this was not being properly handled. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent f50b0e5 commit 0145866

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/refactoring/digest.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ export function computeResourceDigests(template: CloudFormationTemplate): Record
4949
const refTarget = Array.isArray(value['Fn::GetAtt']) ? value['Fn::GetAtt'][0] : value['Fn::GetAtt'].split('.')[0];
5050
return [refTarget];
5151
}
52+
const result = [];
5253
if ('DependsOn' in value) {
53-
return [value.DependsOn];
54+
if (Array.isArray(value.DependsOn)) {
55+
result.push(...value.DependsOn);
56+
} else {
57+
result.push(value.DependsOn);
58+
}
5459
}
55-
return Object.values(value).flatMap(findDependencies);
60+
result.push(...Object.values(value).flatMap(findDependencies));
61+
return result;
5662
};
5763

5864
for (const [id, res] of Object.entries(resources)) {

packages/@aws-cdk/toolkit-lib/test/api/refactoring/refactoring.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,42 @@ describe('computeResourceDigests', () => {
199199
expect(result.Topic1).toEqual(result.Topic2);
200200
});
201201

202+
test('different resources - DependsOn plus Ref in properties', () => {
203+
const template = {
204+
Resources: {
205+
Bucket1: {
206+
Type: 'AWS::S3::Bucket',
207+
Properties: { Prop: 'my-bucket' },
208+
},
209+
Bucket2: {
210+
Type: 'AWS::S3::Bucket',
211+
Properties: { Prop: 'my-bucket' },
212+
},
213+
Bucket3: {
214+
Type: 'AWS::S3::Bucket',
215+
Properties: { AnotherProp: 'foobar' },
216+
},
217+
Topic1: {
218+
Type: 'AWS::SNS::Topic',
219+
DependsOn: 'Bucket1',
220+
Properties: {
221+
DisplayName: 'my-topic',
222+
},
223+
},
224+
Topic2: {
225+
Type: 'AWS::SNS::Topic',
226+
DependsOn: 'Bucket2',
227+
Properties: {
228+
DisplayName: 'my-topic',
229+
SomeRef: { Ref: 'Bucket3' },
230+
},
231+
},
232+
},
233+
};
234+
const result = computeResourceDigests(template);
235+
expect(result.Topic1).not.toEqual(result.Topic2);
236+
});
237+
202238
test('different resources - DependsOn', () => {
203239
const template = {
204240
Resources: {

0 commit comments

Comments
 (0)