From 7ba42e85c0c6349fc1699490ce9b0e9ae7c4ea7e Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Thu, 4 Jul 2024 10:15:56 -0700 Subject: [PATCH] Fix type checking in if/then --- .../fargate_properties.json | 43 +++++++++++++------ .../ecs/test_ecs_task_fargate_properties.py | 10 ++++- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_properties.json b/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_properties.json index bdcfb82445..5ab80ac842 100644 --- a/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_properties.json +++ b/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_properties.json @@ -16,27 +16,42 @@ ] }, "then": { + "if": { + "properties": { + "Cpu": { + "type": [ + "string", + "integer" + ] + } + }, + "required": [ + "Cpu" + ] + }, "not": { "required": [ "PlacementConstraints" ] }, - "properties": { - "Cpu": { - "enum": [ - 256, - 512, - 1024, - 2048, - 4096, - 8192, - 16384 - ] - } - }, "required": [ "Cpu", "Memory" - ] + ], + "then": { + "properties": { + "Cpu": { + "enum": [ + 256, + 512, + 1024, + 2048, + 4096, + 8192, + 16384 + ] + } + } + } } } diff --git a/test/unit/rules/resources/ecs/test_ecs_task_fargate_properties.py b/test/unit/rules/resources/ecs/test_ecs_task_fargate_properties.py index 803fbb63a4..f68d72a58f 100644 --- a/test/unit/rules/resources/ecs/test_ecs_task_fargate_properties.py +++ b/test/unit/rules/resources/ecs/test_ecs_task_fargate_properties.py @@ -75,6 +75,14 @@ def rule(): ) ], ), + ( + { + "RequiresCompatibilities": ["FARGATE"], + "Cpu": {"Ref": "MyParameter"}, + "Memory": "512", + }, + [], + ), ( { "RequiresCompatibilities": ["FARGATE"], @@ -87,7 +95,7 @@ def rule(): rule=TaskFargateProperties(), path=deque(["Cpu"]), validator="enum", - schema_path=deque(["then", "properties", "Cpu", "enum"]), + schema_path=deque(["then", "then", "properties", "Cpu", "enum"]), ) ], ),