Skip to content

Commit 3b47042

Browse files
authored
Fix an issue with E3044 (#3670)
1 parent 05be958 commit 3b47042

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

src/cfnlint/data/schemas/extensions/aws_ecs_service/fargate.json

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
{
22
"if": {
3-
"properties": {
4-
"LaunchType": {
5-
"enum": [
6-
"FARGATE",
7-
"EXTERNAL"
8-
]
3+
"anyOf": [
4+
{
5+
"properties": {
6+
"LaunchType": {
7+
"enum": [
8+
"FARGATE"
9+
]
10+
},
11+
"SchedulingStrategy": {
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"LaunchType"
17+
],
18+
"type": "object"
919
},
10-
"SchedulingStrategy": {
11-
"type": "string"
20+
{
21+
"properties": {
22+
"DeploymentController": {
23+
"properties": {
24+
"Type": {
25+
"enum": [
26+
"CODE_DEPLOY",
27+
"EXTERNAL"
28+
]
29+
}
30+
},
31+
"required": [
32+
"Type"
33+
],
34+
"type": "object"
35+
},
36+
"SchedulingStrategy": {
37+
"type": "string"
38+
}
39+
},
40+
"required": [
41+
"DeploymentController"
42+
],
43+
"type": "object"
1244
}
13-
},
14-
"required": [
15-
"LaunchType"
16-
],
17-
"type": "object"
45+
]
1846
},
1947
"then": {
2048
"properties": {

src/cfnlint/rules/resources/ecs/FargateDeploymentSchedulingStrategy.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
from __future__ import annotations
77

8-
from typing import Any
9-
108
import cfnlint.data.schemas.extensions.aws_ecs_service
11-
from cfnlint.jsonschema import ValidationError
129
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails
1310

1411

@@ -19,8 +16,7 @@ class FargateDeploymentSchedulingStrategy(CfnLintJsonSchema):
1916
"use SchedulingStrategy of REPLICA"
2017
)
2118
description = (
22-
"When using a TargetType of Fargate or External the SchedulingStrategy "
23-
"has to be Replica"
19+
"When using a LaunchType of Fargate the SchedulingStrategy " "has to be Replica"
2420
)
2521
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html#cfn-ecs-service-schedulingstrategy"
2622
tags = ["properties", "ecs", "service", "container", "fargate"]
@@ -32,7 +28,5 @@ def __init__(self) -> None:
3228
module=cfnlint.data.schemas.extensions.aws_ecs_service,
3329
filename="fargate.json",
3430
),
31+
all_matches=True,
3532
)
36-
37-
def message(self, instance: Any, err: ValidationError) -> str:
38-
return err.message

test/unit/rules/resources/ecs/test_ecs_fargate.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,43 @@ def rule():
4646
},
4747
[],
4848
),
49+
(
50+
{
51+
"LaunchType": "EXTERNAL",
52+
"SchedulingStrategy": "DAEMON",
53+
},
54+
[],
55+
),
56+
(
57+
{
58+
"LaunchType": "EXTERNAL",
59+
"SchedulingStrategy": "DAEMON",
60+
"DeploymentController": {"Type": "ECS"},
61+
},
62+
[],
63+
),
64+
(
65+
{
66+
"LaunchType": "EXTERNAL",
67+
"SchedulingStrategy": "DAEMON",
68+
"DeploymentController": {"Type": "CODE_DEPLOY"},
69+
},
70+
[
71+
ValidationError(
72+
"'REPLICA' was expected",
73+
rule=FargateDeploymentSchedulingStrategy(),
74+
path=deque(["SchedulingStrategy"]),
75+
validator="const",
76+
schema_path=deque(
77+
["then", "properties", "SchedulingStrategy", "const"]
78+
),
79+
)
80+
],
81+
),
4982
(
5083
{
5184
"LaunchType": "FARGATE",
52-
"SchedulingStrategy": "Foo",
85+
"SchedulingStrategy": "DAEMON",
5386
},
5487
[
5588
ValidationError(

0 commit comments

Comments
 (0)