File tree Expand file tree Collapse file tree
test/unit/module/conditions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -266,14 +266,24 @@ def build_scenerios_on_region(
266266 if not isinstance (condition_name , str ):
267267 return
268268 cnf_region = self ._cnf .copy ()
269+ found_region = False
269270 for eql in self ._conditions [condition_name ].equals :
270271 is_region , equal_region = eql .is_region
271272 if is_region :
273+ found_region = True
272274 if equal_region == region :
273275 cnf_region .add_prop (And (self ._solver_params [eql .hash ]))
274276 else :
275277 cnf_region .add_prop (Not (self ._solver_params [eql .hash ]))
276278
279+ # The condition doesn't use a region parameter so it can be True or False
280+ # Note: It is possible its a hard coded condition but
281+ # for now we will return True and False
282+ if not found_region :
283+ yield True
284+ yield False
285+ return
286+
277287 cnf_test = cnf_region .copy ()
278288 cnf_test .add_prop (
279289 self ._conditions [condition_name ].build_true_cnf (self ._solver_params )
Original file line number Diff line number Diff line change @@ -180,3 +180,52 @@ def test_check_can_be_good_when_condition_value(self):
180180 {"IsGamma" : False },
181181 ],
182182 )
183+
184+ def test_check_condition_region (self ):
185+ """Regional based condition testing"""
186+ template = decode_str (
187+ """
188+ Parameters:
189+ Environment:
190+ Type: String
191+ AllowedValues: ["prod", "dev", "stage"]
192+ Conditions:
193+ IsUsEast1: !Equals [!Ref AWS::Region, "us-east-1"]
194+ IsUsWest2: !Equals ["us-west-2", !Ref AWS::Region]
195+ IsProd: !Equals [!Ref Environment, "prod"]
196+ """
197+ )[0 ]
198+
199+ cfn = Template ("" , template )
200+ self .assertEqual (len (cfn .conditions ._conditions ), 3 )
201+ self .assertListEqual (
202+ list (cfn .conditions .build_scenerios_on_region ("IsUsEast1" , "us-east-1" )),
203+ [
204+ True ,
205+ ],
206+ )
207+ self .assertListEqual (
208+ list (cfn .conditions .build_scenerios_on_region ("IsUsEast1" , "us-west-2" )),
209+ [
210+ False ,
211+ ],
212+ )
213+ self .assertListEqual (
214+ list (cfn .conditions .build_scenerios_on_region ("IsUsWest2" , "us-west-2" )),
215+ [
216+ True ,
217+ ],
218+ )
219+ self .assertListEqual (
220+ list (cfn .conditions .build_scenerios_on_region ("IsUsWest2" , "us-east-1" )),
221+ [
222+ False ,
223+ ],
224+ )
225+ self .assertListEqual (
226+ list (cfn .conditions .build_scenerios_on_region ("IsProd" , "us-east-1" )),
227+ [
228+ True ,
229+ False ,
230+ ],
231+ )
You can’t perform that action at this time.
0 commit comments