@@ -23,14 +23,14 @@ def test_conditions_with_rules(self):
23
23
Assertions:
24
24
- Assert:
25
25
Fn::And:
26
- - !Condition IsProd
27
- - !Condition IsUsEast1
26
+ - !Equals [!Ref Environment, "prod"]
27
+ - !Equals [!Ref "AWS::Region", "us-east-1"]
28
28
Rule2:
29
29
Assertions:
30
30
- Assert:
31
31
Fn::Or:
32
- - !Condition IsProd
33
- - !Condition IsUsEast1
32
+ - !Equals [!Ref Environment, "prod"]
33
+ - !Equals [!Ref "AWS::Region", "us-east-1"]
34
34
"""
35
35
)[0 ]
36
36
@@ -79,9 +79,9 @@ def test_conditions_with_rules_implies(self):
79
79
IsUsEast1: !Equals [!Ref "AWS::Region", "us-east-1"]
80
80
Rules:
81
81
Rule:
82
- RuleCondition: !Condition IsProd
82
+ RuleCondition: !Equals [!Ref Environment, "prod"]
83
83
Assertions:
84
- - Assert: !Condition IsUsEast1
84
+ - Assert: !Equals [!Ref "AWS::Region", "us-east-1"]
85
85
86
86
"""
87
87
)[0 ]
@@ -143,11 +143,11 @@ def test_conditions_with_multiple_rules(self):
143
143
Rule1:
144
144
RuleCondition: !Equals [!Ref Environment, "prod"]
145
145
Assertions:
146
- - Assert: !Condition IsUsEast1
146
+ - Assert: !Equals [!Ref "AWS::Region", "us-east-1"]
147
147
Rule2:
148
148
RuleCondition: !Equals [!Ref Environment, "dev"]
149
149
Assertions:
150
- - Assert: !Not [!Condition IsUsEast1 ]
150
+ - Assert: !Not [!Equals [!Ref "AWS::Region", "us-east-1"] ]
151
151
"""
152
152
)[0 ]
153
153
@@ -366,6 +366,95 @@ def test_fn_equals_assertions_ref_never_satisfiable(self):
366
366
)
367
367
)
368
368
369
+ def test_conditions_with_rules_and_parameters (self ):
370
+ template = decode_str (
371
+ """
372
+ Conditions:
373
+ DeployGateway: !Equals
374
+ - !Ref 'DeployGateway'
375
+ - 'true'
376
+ DeployVpc: !Equals
377
+ - !Ref 'DeployVpc'
378
+ - 'true'
379
+ Parameters:
380
+ DeployAnything:
381
+ AllowedValues:
382
+ - 'false'
383
+ - 'true'
384
+ Type: 'String'
385
+ DeployGateway:
386
+ AllowedValues:
387
+ - 'false'
388
+ - 'true'
389
+ Type: 'String'
390
+ DeployVpc:
391
+ AllowedValues:
392
+ - 'false'
393
+ - 'true'
394
+ Type: 'String'
395
+ Rules:
396
+ DeployGateway:
397
+ Assertions:
398
+ - Assert: !Or
399
+ - !Equals
400
+ - !Ref 'DeployAnything'
401
+ - 'true'
402
+ - !Equals
403
+ - !Ref 'DeployGateway'
404
+ - 'false'
405
+ DeployVpc:
406
+ Assertions:
407
+ - Assert: !Or
408
+ - !Equals
409
+ - !Ref 'DeployGateway'
410
+ - 'true'
411
+ - !Equals
412
+ - !Ref 'DeployVpc'
413
+ - 'false'
414
+ Resources:
415
+ InternetGateway:
416
+ Condition: 'DeployGateway'
417
+ Type: 'AWS::EC2::InternetGateway'
418
+ InternetGatewayAttachment:
419
+ Condition: 'DeployVpc'
420
+ Type: 'AWS::EC2::VPCGatewayAttachment'
421
+ Properties:
422
+ InternetGatewayId: !Ref 'InternetGateway'
423
+ VpcId: !Ref 'Vpc'
424
+ """
425
+ )[0 ]
426
+
427
+ cfn = Template ("" , template )
428
+ self .assertEqual (len (cfn .conditions ._conditions ), 2 )
429
+ self .assertEqual (len (cfn .conditions ._rules ), 2 )
430
+
431
+ self .assertListEqual (
432
+ [equal .hash for equal in cfn .conditions ._rules [0 ].equals ],
433
+ [
434
+ "d0d70a1e66dc83d7a0fce24c2eca396af1f34e53" ,
435
+ "bbf5c94c1a4b5a79c7a7863fe9463884cb422450" ,
436
+ ],
437
+ )
438
+
439
+ self .assertTrue (
440
+ cfn .conditions .satisfiable (
441
+ {},
442
+ {},
443
+ )
444
+ )
445
+
446
+ self .assertTrue (
447
+ cfn .conditions .check_implies ({"DeployVpc" : True }, "DeployGateway" )
448
+ )
449
+
450
+ self .assertFalse (
451
+ cfn .conditions .check_implies ({"DeployVpc" : False }, "DeployGateway" )
452
+ )
453
+
454
+ self .assertFalse (
455
+ cfn .conditions .check_implies ({"DeployGateway" : False }, "DeployVpc" )
456
+ )
457
+
369
458
370
459
class TestAssertion (TestCase ):
371
460
def test_assertion_errors (self ):
@@ -405,7 +494,7 @@ def test_init_rules_with_wrong_assertions_type(self):
405
494
Assertions: {"Foo": "Bar"}
406
495
Rule2:
407
496
Assertions:
408
- - Assert: !Condition IsUsEast1
497
+ - Assert: !Equals [!Ref "AWS::Region", "us-east-1"]
409
498
"""
410
499
)[0 ]
411
500
@@ -425,8 +514,8 @@ def test_init_rules_with_no_keys(self):
425
514
Assertions:
426
515
- Assert:
427
516
Fn::Or:
428
- - !Condition IsNotUsEast1
429
- - !Condition IsUsEast1
517
+ - !Not [!Equals [!Ref "AWS::Region", "us-east-1"]]
518
+ - !Equals [!Ref "AWS::Region", "us-east-1"]
430
519
Rule3: []
431
520
"""
432
521
)[0 ]
0 commit comments