diff --git a/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_cpu_memory.json b/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_cpu_memory.json index 3fc18efad7..4f6f376241 100644 --- a/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_cpu_memory.json +++ b/src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_cpu_memory.json @@ -34,12 +34,27 @@ { "properties": { "Cpu": { - "enum": [ - "256" - ] + "else": { + "pattern": "^\\.25\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "256" + ] + } }, "Memory": { "enum": [ + "0.5 GB", + "1 GB", + "2 GB", "512", "1024", "2048" @@ -50,84 +65,228 @@ { "properties": { "Cpu": { - "enum": [ - "512" - ] + "else": { + "pattern": "^\\.5\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "512" + ] + } }, "Memory": { - "maximum": 4096, - "minimum": 1024, - "multipleOf": 1024 + "else": { + "pattern": "^(1|2|3|4)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 4096, + "minimum": 1024, + "multipleOf": 1024 + } } } }, { "properties": { "Cpu": { - "enum": [ - "1024" - ] + "else": { + "pattern": "^1\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "1024" + ] + } }, "Memory": { - "maximum": 8192, - "minimum": 2048, - "multipleOf": 1024 + "else": { + "pattern": "^(2|3|4|5|6|7|8)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 8192, + "minimum": 2048, + "multipleOf": 1024 + } } } }, { "properties": { "Cpu": { - "enum": [ - "2048" - ] + "else": { + "pattern": "^2\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "2048" + ] + } }, "Memory": { - "maximum": 16384, - "minimum": 4096, - "multipleOf": 1024 + "else": { + "pattern": "^(4|5|6|7|8|9|10|11|12|13|14|15|16)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 16384, + "minimum": 4096, + "multipleOf": 1024 + } } } }, { "properties": { "Cpu": { - "enum": [ - "4096" - ] + "else": { + "pattern": "^4\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "4096" + ] + } }, "Memory": { - "maximum": 30720, - "minimum": 8192, - "multipleOf": 1024 + "else": { + "pattern": "^(8|9|1[0-9]|2[0-9]|30)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 30720, + "minimum": 8192, + "multipleOf": 1024 + } } } }, { "properties": { "Cpu": { - "enum": [ - "8192" - ] + "else": { + "pattern": "^8\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "8192" + ] + } }, "Memory": { - "maximum": 61440, - "minimum": 16384, - "multipleOf": 4096 + "else": { + "pattern": "^(16|20|24|28|32|36|40|44|48|52|56|60)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 61440, + "minimum": 16384, + "multipleOf": 4096 + } } } }, { "properties": { "Cpu": { - "enum": [ - "16384" - ] + "else": { + "pattern": "^16\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "16384" + ] + } }, "Memory": { - "maximum": 122880, - "minimum": 32768, - "multipleOf": 8192 + "else": { + "pattern": "^(32|40|48|56|64|72|80|88|96|104|112|120)\\s*(?i)GB$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "maximum": 122880, + "minimum": 32768, + "multipleOf": 8192 + } } } } 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 c590df4986..f0326beeb0 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 @@ -41,15 +41,27 @@ "then": { "properties": { "Cpu": { - "enum": [ - "256", - "512", - "1024", - "2048", - "4096", - "8192", - "16384" - ] + "else": { + "pattern": "^(\\.25|\\.5|1|2|4|8|16)\\s*(?i)vCpu$" + }, + "if": { + "pattern": "^\\d+$", + "type": [ + "integer", + "string" + ] + }, + "then": { + "enum": [ + "256", + "512", + "1024", + "2048", + "4096", + "8192", + "16384" + ] + } } } } diff --git a/test/unit/rules/resources/ecs/test_ecs_fargate_cpu_memory.py b/test/unit/rules/resources/ecs/test_ecs_fargate_cpu_memory.py index 7aacac0af5..9c315f1979 100644 --- a/test/unit/rules/resources/ecs/test_ecs_fargate_cpu_memory.py +++ b/test/unit/rules/resources/ecs/test_ecs_fargate_cpu_memory.py @@ -36,6 +36,14 @@ def rule(): }, [], ), + ( + { + "RequiresCompatibilities": ["FARGATE"], + "Cpu": ".5 vCPU", + "Memory": "1 GB", + }, + [], + ), ( { "RequiresCompatibilities": ["FARGATE"], @@ -55,23 +63,31 @@ def rule(): ( { "RequiresCompatibilities": ["FARGATE"], - "Cpu": 4096, + "Cpu": "4 vcpu", "Memory": 30720, }, [], ), + ( + { + "RequiresCompatibilities": ["FARGATE"], + "Cpu": "4 vcpu", + "Memory": "22 gb", + }, + [], + ), ( { "RequiresCompatibilities": ["FARGATE"], "Cpu": 8192, - "Memory": 16384, + "Memory": "16 GB", }, [], ), ( { "RequiresCompatibilities": ["FARGATE"], - "Cpu": 16384, + "Cpu": "16 vCpU", "Memory": 122880, }, [], @@ -92,6 +108,22 @@ def rule(): ) ], ), + ( + { + "RequiresCompatibilities": ["FARGATE"], + "Cpu": 16384, + "Memory": "1 GB", + }, + [ + ValidationError( + "Cpu 16384 is not compatible with memory '1 GB'", + rule=FargateCpuMemory(), + path=deque([]), + validator="anyOf", + schema_path=deque(["then", "anyOf"]), + ) + ], + ), ( { "RequiresCompatibilities": ["FARGATE", "Foo"], 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 846bd2c023..b2935bd6b2 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 @@ -28,6 +28,14 @@ def rule(): }, [], ), + ( + { + "RequiresCompatibilities": ["FARGATE"], + "Cpu": ".25 vCpU", + "Memory": "512", + }, + [], + ), ( { "RequiresCompatibilities": ["FARGATE"], @@ -92,13 +100,15 @@ def rule(): [ ValidationError( ( - "128 is not one of ['256', '512', '1024', " - "'2048', '4096', '8192', '16384']" + "128 is not one of ['256', '512', '1024', '2048', " + "'4096', '8192', '16384']" ), rule=TaskFargateProperties(), path=deque(["Cpu"]), validator="enum", - schema_path=deque(["then", "then", "properties", "Cpu", "enum"]), + schema_path=deque( + ["then", "then", "properties", "Cpu", "then", "enum"] + ), ) ], ),