From 7a0730a3e95d1769d1e940e83cde30eae5b2acd3 Mon Sep 17 00:00:00 2001 From: Jiati Le Date: Tue, 21 Feb 2023 13:44:36 -0500 Subject: [PATCH] Fix Fargate strategy rule to handle non string properties Change: Intrinsic functions can be used for resource properties and previously this rule checker doesn't handle such scenario. --- .../ecs/FargateDeploymentSchedulingStrategy.py | 14 +++++++++----- .../ecs/test_fargate_scheduling_strategy.yaml | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py b/src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py index 9d9b991278..1e00011294 100644 --- a/src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py +++ b/src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py @@ -20,9 +20,13 @@ def match(self, cfn): path = ecs_service["Path"] properties = ecs_service["Value"] if isinstance(properties, dict): - if properties.get("LaunchType", None) != "Fargate": - continue - if properties.get("SchedulingStrategy", None) != "REPLICA": - error_message = f"Fargate service only support REPLICA as scheduling strategy at {'/'.join(map(str, path))}" - matches.append(RuleMatch(path, error_message)) + launch_type = properties.get("LaunchType", None) + if isinstance(launch_type, str) and launch_type == "Fargate": + scheduling_strategy = properties.get("SchedulingStrategy", None) + if ( + isinstance(scheduling_strategy, str) + and scheduling_strategy != "REPLICA" + ): + error_message = f"Fargate service only support REPLICA as scheduling strategy at {'/'.join(map(str, path))}" + matches.append(RuleMatch(path, error_message)) return matches diff --git a/test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml b/test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml index 5614da29cb..0331566ce8 100644 --- a/test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml +++ b/test/fixtures/templates/good/resources/ecs/test_fargate_scheduling_strategy.yaml @@ -14,3 +14,8 @@ Resources: Properties: LaunchType: EXTERNAL SchedulingStrategy: DAEMON + Service4: + Type: AWS::ECS::Service + Properties: + LaunchType: !Join ["", ["FAR", "GATE"]] + SchedulingStrategy: DAEMON