Skip to content

Commit

Permalink
Fix issue with resource types when condition is t/f (#3813)
Browse files Browse the repository at this point in the history
* Fix issue with resource types when condition is t/f

* Update to logic
  • Loading branch information
kddejong authored Nov 7, 2024
1 parent c5b4c21 commit 3c42504
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cfnlint/rules/resources/ResourceType.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def validate(self, validator: Validator, keywords: Any, instance: Any, schema: A
if validator.is_type(resource_condition, "string"):
if validator.cfn is None:
continue
if False in validator.cfn.conditions.build_scenerios_on_region(
if True not in validator.cfn.conditions.build_scenerios_on_region(
resource_condition, region
):
continue
Expand Down
28 changes: 28 additions & 0 deletions test/unit/rules/resources/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,31 @@ def test_types_with_conditions_false(self, cfn):
)

self.assertListEqual(errors, [], errors)

@patch("cfnlint.template.Template", autospec=True)
def test_types_with_conditions_false_and_true(self, cfn):
cfn = Mock()
cfn.conditions = Mock()
cfn.conditions.build_scenerios_on_region.return_value = [True, False]
validator = CfnTemplateValidator({}).evolve(cfn=cfn)
errors = list(
self.rule.validate(
validator,
"cfnResources",
{"Type": "Foo::Bar::Type", "Condition": "IsUsEast1"},
{},
)
)

self.assertListEqual(
errors,
[
ValidationError(
"Resource type 'Foo::Bar::Type' does not exist in 'us-east-1'",
path=deque(["Type"]),
schema_path=deque([]),
rule=ResourceType(),
),
],
errors,
)

0 comments on commit 3c42504

Please sign in to comment.