Skip to content

Commit 373738e

Browse files
authored
Update rule E3049 to only trigger when host port is 0 (#3543)
1 parent 63cadf4 commit 373738e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ def _filter_port_mappings(
172172
if not isinstance(container_port, (str, int)):
173173
continue
174174
if str(port) == str(container_port):
175-
for _, host_part_validator in get_value_from_path(
175+
for host_port, host_part_validator in get_value_from_path(
176176
container_port_validator,
177177
port_mapping,
178178
path=deque(["HostPort"]),
179179
):
180-
yield host_part_validator
180+
if str(host_port) == "0":
181+
yield host_part_validator
181182

182183
def validate(
183184
self, validator: Validator, _: Any, instance: Any, schema: dict[str, Any]
@@ -212,4 +213,5 @@ def validate(
212213
"has to have a 'HealthCheckPort' of 'traffic-port'",
213214
path_override=health_check_port_validator.context.path.path,
214215
validator=err_validator,
216+
rule=self,
215217
)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def rule():
268268
path_override=deque(
269269
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
270270
),
271+
rule=ServiceDynamicPorts(),
271272
)
272273
],
273274
),
@@ -330,6 +331,7 @@ def rule():
330331
path_override=deque(
331332
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
332333
),
334+
rule=ServiceDynamicPorts(),
333335
)
334336
],
335337
),
@@ -359,6 +361,7 @@ def rule():
359361
path_override=deque(
360362
["Resources", "TargetGroup", "Properties", "HealthCheckPort"]
361363
),
364+
rule=ServiceDynamicPorts(),
362365
)
363366
],
364367
),
@@ -552,6 +555,29 @@ def rule():
552555
deque(["Resources", "Service", "Properties"]),
553556
[],
554557
),
558+
(
559+
{
560+
"Resources": {
561+
"TaskDefinition": jsonpatch.apply_patch(
562+
dict(_task_definition),
563+
[
564+
{
565+
"op": "replace",
566+
"path": (
567+
"/Properties/ContainerDefinitions/"
568+
"0/PortMappings/0/HostPort"
569+
),
570+
"value": "30",
571+
},
572+
],
573+
),
574+
"TargetGroup": dict(_target_group),
575+
"Service": dict(_service),
576+
}
577+
},
578+
deque(["Resources", "Service", "Properties"]),
579+
[],
580+
),
555581
],
556582
indirect=["template"],
557583
)

0 commit comments

Comments
 (0)