Skip to content

Commit

Permalink
fix(cfn-include): allow Conditions to reference Mappings in their def…
Browse files Browse the repository at this point in the history
…initions (#10105)

Fixes #10099

----

*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 committed Sep 2, 2020
1 parent 9c1b0c1 commit aa2068f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/cloudformation-include/lib/cfn-include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ export class CfnInclude extends core.CfnElement {
? self.getOrCreateCondition(cName)
: undefined;
},
findMapping() { throw new Error('Using FindInMap in Condition definitions is not allowed'); },
findMapping(mappingName: string): core.CfnMapping | undefined {
return self.mappings[mappingName];
},
},
context: cfn_parse.CfnParsingContext.CONDITIONS,
parameters: this.parametersToReplace,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Conditions": {
"AlwaysTrue": {
"Fn::Equals": [
{ "Fn::FindInMap": ["Mapping01", "Key01", "Name"] },
"Value01"
]
}
},
"Mappings" : {
"Mapping01" : {
"Key01" : {
"Name" : "Value01"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ describe('CDK Include', () => {
);
});

test('allows Conditions to reference Mappings', () => {
includeTestTemplate(stack, 'condition-using-mapping.json');

expect(stack).toMatchTemplate(
loadTestFileToJsObject('condition-using-mapping.json'),
);
});

test('correctly change references to Conditions when renaming them', () => {
const cfnTemplate = includeTestTemplate(stack, 'condition-same-name-as-resource.json');
const alwaysFalse = cfnTemplate.getCondition('AlwaysFalse');
Expand Down

0 comments on commit aa2068f

Please sign in to comment.