Skip to content

Commit 3409497

Browse files
authored
Update E3054 to not alert on awsvpc (#3593)
1 parent 5b268db commit 3409497

File tree

2 files changed

+99
-13
lines changed

2 files changed

+99
-13
lines changed

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,35 @@ def _get_task_definition_properties(
7777
)
7878
if not task_definition:
7979
return
80-
8180
for capabilities, capabilities_validator in get_value_from_path(
8281
task_definition_validator,
8382
task_definition,
8483
path=deque(["Properties", "RequiresCompatibilities"]),
8584
):
86-
if capabilities is None:
87-
yield capabilities, capabilities_validator
88-
continue
89-
if not isinstance(capabilities, list):
90-
continue
91-
for capibility, _ in get_value_from_path(
85+
for network_mode, network_mode_validator in get_value_from_path(
9286
capabilities_validator,
93-
capabilities,
94-
path=deque(["*"]),
87+
task_definition,
88+
path=deque(["Properties", "NetworkMode"]),
9589
):
96-
if isinstance(capibility, dict) or capibility == "FARGATE":
97-
break
98-
else:
99-
yield capabilities, capabilities_validator
90+
91+
if network_mode == "awsvpc" or network_mode_validator.is_type(
92+
network_mode, "object"
93+
):
94+
continue
95+
if capabilities is None:
96+
yield capabilities, capabilities_validator
97+
continue
98+
if not isinstance(capabilities, list):
99+
continue
100+
for capibility, _ in get_value_from_path(
101+
network_mode_validator,
102+
capabilities,
103+
path=deque(["*"]),
104+
):
105+
if isinstance(capibility, dict) or capibility == "FARGATE":
106+
break
107+
else:
108+
yield capabilities, capabilities_validator
100109

101110
def validate(
102111
self, validator: Validator, _: Any, instance: Any, schema: dict[str, Any]

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,83 @@ def rule():
315315
deque(["Resources", "Service", "Properties"]),
316316
[],
317317
),
318+
(
319+
{
320+
"Resources": {
321+
"TaskDefinition": jsonpatch.apply_patch(
322+
dict(_task_definition),
323+
[
324+
{
325+
"op": "add",
326+
"path": "/Properties/NetworkMode",
327+
"value": "awsvpc",
328+
},
329+
{
330+
"op": "remove",
331+
"path": "/Properties/RequiresCompatibilities",
332+
},
333+
],
334+
),
335+
"Service": dict(_service),
336+
},
337+
},
338+
deque(["Resources", "Service", "Properties"]),
339+
[],
340+
),
341+
(
342+
{
343+
"Parameters": {"MyNetworkMode": {"Type": "String"}},
344+
"Resources": {
345+
"TaskDefinition": jsonpatch.apply_patch(
346+
dict(_task_definition),
347+
[
348+
{
349+
"op": "add",
350+
"path": "/Properties/NetworkMode",
351+
"value": {"Ref": "MyNetworkMode"},
352+
},
353+
{
354+
"op": "remove",
355+
"path": "/Properties/RequiresCompatibilities",
356+
},
357+
],
358+
),
359+
"Service": dict(_service),
360+
},
361+
},
362+
deque(["Resources", "Service", "Properties"]),
363+
[],
364+
),
365+
(
366+
{
367+
"Resources": {
368+
"TaskDefinition": jsonpatch.apply_patch(
369+
dict(_task_definition),
370+
[
371+
{
372+
"op": "add",
373+
"path": "/Properties/NetworkMode",
374+
"value": "host",
375+
},
376+
{
377+
"op": "remove",
378+
"path": "/Properties/RequiresCompatibilities",
379+
},
380+
],
381+
),
382+
"Service": dict(_service),
383+
},
384+
},
385+
deque(["Resources", "Service", "Properties"]),
386+
[
387+
ValidationError(
388+
("'RequiresCompatibilities' is a required property"),
389+
validator="required",
390+
rule=ServiceFargate(),
391+
path_override=deque(["Resources", "TaskDefinition", "Properties"]),
392+
)
393+
],
394+
),
318395
],
319396
indirect=["template"],
320397
)

0 commit comments

Comments
 (0)