-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cloudformation condition chaining (#1494)
Change `conditionXx` methods to accept an interface `IConditionExpression` instead of concrete class and implement this interface by the `Condition` construct. This enables chaining conditions like so: const cond1, cond2, cond, cond4 = new cdk.Condition(...) Fn.conditionOr(cond1, cond2, Fn.conditionAnd(cond3, cond4)) Fixes #1457
- Loading branch information
Elad Ben-Israel
authored
Jan 8, 2019
1 parent
81b4174
commit 2169015
Showing
5 changed files
with
116 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/@aws-cdk/cdk/test/cloudformation/test.condition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Test } from 'nodeunit'; | ||
import cdk = require('../../lib'); | ||
|
||
export = { | ||
'chain conditions'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const param = new cdk.Parameter(stack, 'Param1', { type: 'String' }); | ||
const cond1 = new cdk.Condition(stack, 'Condition1', { expression: cdk.Fn.conditionEquals("a", "b") }); | ||
const cond2 = new cdk.Condition(stack, 'Condition2', { expression: cdk.Fn.conditionContains([ "a", "b", "c" ], "c") }); | ||
const cond3 = new cdk.Condition(stack, 'Condition3', { expression: cdk.Fn.conditionEquals(param, "hello") }); | ||
|
||
// WHEN | ||
new cdk.Condition(stack, 'Condition4', { | ||
expression: cdk.Fn.conditionOr(cond1, cond2, cdk.Fn.conditionNot(cond3)) | ||
}); | ||
|
||
// THEN | ||
test.deepEqual(stack.toCloudFormation(), { | ||
Parameters: { Param1: { Type: 'String' } }, | ||
Conditions: { | ||
Condition1: { 'Fn::Equals': [ 'a', 'b' ] }, | ||
Condition2: { 'Fn::Contains': [ [ 'a', 'b', 'c' ], 'c' ] }, | ||
Condition3: { 'Fn::Equals': [ { Ref: 'Param1' }, 'hello' ] }, | ||
Condition4: { 'Fn::Or': [ | ||
{ Condition: 'Condition1' }, | ||
{ Condition: 'Condition2' }, | ||
{ 'Fn::Not': [ { Condition: 'Condition3' } ] } ] } } }); | ||
|
||
test.done(); | ||
} | ||
}; |