Skip to content

Commit

Permalink
fix(core): can't have multiple CfnRules in a Stack (#9500)
Browse files Browse the repository at this point in the history
When we changed the merging behavior in #8251,
we forgot to account for the 'Rules' section.
To prevent that error from happening again,
let's default to merging objects without duplicates.

Fixes #9485

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Aug 7, 2020
1 parent 1670289 commit 76a7bfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 1 addition & 9 deletions packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,8 @@ function mergeSection(section: string, val1: any, val2: any): any {
return val1 ?? val2;
case 'Transform':
return mergeSets(val1, val2);
case 'Resources':
case 'Conditions':
case 'Parameters':
case 'Outputs':
case 'Mappings':
case 'Metadata':
return mergeObjectsWithoutDuplicates(section, val1, val2);
default:
throw new Error(`CDK doesn't know how to merge two instances of the CFN template section '${section}' - ` +
'please remove one of them from your code');
return mergeObjectsWithoutDuplicates(section, val1, val2);
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/core/test/test.rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@ export = {

test.done();
},

'a template can contain multiple Rules'(test: Test) {
const stack = new Stack();

new CfnRule(stack, 'Rule1');
new CfnRule(stack, 'Rule2');

test.deepEqual(toCloudFormation(stack), {
Rules: {
Rule1: {},
Rule2: {},
},
});

test.done();
},
};

0 comments on commit 76a7bfd

Please sign in to comment.