Skip to content

Commit

Permalink
Fix issue with resource types when condition is t/f
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Nov 7, 2024
1 parent adf24d0 commit 9c25de9
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 [False] == 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 9c25de9

Please sign in to comment.