Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with resource types when condition is t/f #3813

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
Loading