-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two new rules to validate fargate tasks
- Loading branch information
Showing
6 changed files
with
365 additions
and
116 deletions.
There are no files selected for viewing
255 changes: 145 additions & 110 deletions
255
src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_cpu_memory.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,149 @@ | ||
{ | ||
"if": { | ||
"properties": { | ||
"RequiresCompatibilities": { | ||
"type": "array", | ||
"contains": { | ||
"type": "string", | ||
"enum": ["FARGATE"] | ||
} | ||
}, | ||
"Cpu": { | ||
"type": ["string", "integer"] | ||
}, | ||
"Memory": { | ||
"type": ["string", "integer"] | ||
} | ||
}, | ||
"required": ["RequiresCompatibilities", "Cpu", "Memory"] | ||
"if": { | ||
"properties": { | ||
"Cpu": { | ||
"type": [ | ||
"string", | ||
"integer" | ||
] | ||
}, | ||
"Memory": { | ||
"type": [ | ||
"string", | ||
"integer" | ||
] | ||
}, | ||
"RequiresCompatibilities": { | ||
"contains": { | ||
"enum": [ | ||
"FARGATE" | ||
], | ||
"type": "string" | ||
}, | ||
"then": { | ||
"anyOf": [ | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["256", 256] | ||
}, | ||
"Memory": { | ||
"enum": [ | ||
"512", | ||
"1024", | ||
"2048", | ||
512, | ||
1024, | ||
2048 | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["512", 512] | ||
}, | ||
"Memory": { | ||
"minimum": 1024, | ||
"maximum": 4096, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["1024", 1024] | ||
}, | ||
"Memory": { | ||
"minimum": 2048, | ||
"maximum": 8192, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["2048", 2048] | ||
}, | ||
"Memory": { | ||
"minimum": 4096, | ||
"maximum": 16384, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["4096", 4096] | ||
}, | ||
"Memory": { | ||
"minimum": 8192, | ||
"maximum": 30720, | ||
"multipleOf": 1024 | ||
|
||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["8192", 8192] | ||
}, | ||
"Memory": { | ||
"minimum": 16384, | ||
"maximum": 61440, | ||
"multipleOf": 4096 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": ["16384", 16384] | ||
}, | ||
"Memory": { | ||
"minimum": 32768, | ||
"maximum": 122880, | ||
"multipleOf": 8192 | ||
} | ||
} | ||
} | ||
] | ||
"type": "array" | ||
} | ||
}, | ||
"required": [ | ||
"RequiresCompatibilities", | ||
"Cpu", | ||
"Memory" | ||
] | ||
}, | ||
"then": { | ||
"anyOf": [ | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
256 | ||
] | ||
}, | ||
"Memory": { | ||
"enum": [ | ||
512, | ||
1024, | ||
2048 | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
512 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 4096, | ||
"minimum": 1024, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
1024 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 8192, | ||
"minimum": 2048, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
2048 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 16384, | ||
"minimum": 4096, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
4096 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 30720, | ||
"minimum": 8192, | ||
"multipleOf": 1024 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
8192 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 61440, | ||
"minimum": 16384, | ||
"multipleOf": 4096 | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
16384 | ||
] | ||
}, | ||
"Memory": { | ||
"maximum": 122880, | ||
"minimum": 32768, | ||
"multipleOf": 8192 | ||
} | ||
} | ||
} | ||
], | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
256, | ||
512, | ||
1024, | ||
2048, | ||
4096, | ||
8192, | ||
16384 | ||
] | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/cfnlint/data/schemas/extensions/aws_ecs_taskdefinition/fargate_properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"if": { | ||
"properties": { | ||
"RequiresCompatibilities": { | ||
"contains": { | ||
"enum": [ | ||
"FARGATE" | ||
], | ||
"type": "string" | ||
}, | ||
"type": "array" | ||
} | ||
}, | ||
"required": [ | ||
"RequiresCompatibilities" | ||
] | ||
}, | ||
"then": { | ||
"not": { | ||
"required": [ | ||
"PlacementConstraints" | ||
] | ||
}, | ||
"properties": { | ||
"Cpu": { | ||
"enum": [ | ||
256, | ||
512, | ||
1024, | ||
2048, | ||
4096, | ||
8192, | ||
16384 | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"Cpu", | ||
"Memory" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from collections import deque | ||
from typing import Any | ||
|
||
import cfnlint.data.schemas.extensions.aws_ecs_taskdefinition | ||
from cfnlint.jsonschema import ValidationResult | ||
from cfnlint.jsonschema.protocols import Validator | ||
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails | ||
|
||
|
||
class TaskFargateProperties(CfnLintJsonSchema): | ||
id = "E3048" | ||
shortdesc = "Validate ECS Fargate tasks have required properties and values" | ||
description = ( | ||
"When using a ECS Fargate task there is a specfic combination " | ||
"of required properties and values" | ||
) | ||
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html#cfn-ecs-taskdefinition-memory" | ||
tags = ["properties", "ecs", "service", "container", "fargate"] | ||
|
||
def __init__(self) -> None: | ||
super().__init__( | ||
keywords=["Resources/AWS::ECS::TaskDefinition/Properties"], | ||
schema_details=SchemaDetails( | ||
module=cfnlint.data.schemas.extensions.aws_ecs_taskdefinition, | ||
filename="fargate_properties.json", | ||
), | ||
all_matches=True, | ||
) | ||
|
||
def validate( | ||
self, validator: Validator, keywords: Any, instance: Any, schema: dict[str, Any] | ||
) -> ValidationResult: | ||
for err in super().validate(validator, keywords, instance, schema): | ||
if err.validator == "not": | ||
err.message = "'PlacementConstraints' isn't supported for Fargate tasks" | ||
err.path = deque(["PlacementConstraints"]) | ||
yield err | ||
continue | ||
yield err |
Oops, something went wrong.