From 6df3ff8ed675ee802c7be5b087a46586d3af370e Mon Sep 17 00:00:00 2001 From: Felipe Freitas Date: Tue, 3 Dec 2024 00:44:50 -0300 Subject: [PATCH] T3 - Fix Hardcoded Container Port --- infra/alb.tf | 4 ++-- infra/ecs.tf | 6 +++--- infra/security_group.tf | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/infra/alb.tf b/infra/alb.tf index f0a045e..7a03a5b 100644 --- a/infra/alb.tf +++ b/infra/alb.tf @@ -14,7 +14,7 @@ module "alb" { listeners = { http = { - port = 8000 + port = local.container_port protocol = "HTTP" forward = { @@ -26,7 +26,7 @@ module "alb" { target_groups = { ecs = { backend_protocol = "HTTP" - backend_port = 8000 + backend_port = local.container_port target_type = "ip" deregistration_delay = 5 load_balancing_cross_zone_enabled = true diff --git a/infra/ecs.tf b/infra/ecs.tf index dd5bc9b..36b9405 100644 --- a/infra/ecs.tf +++ b/infra/ecs.tf @@ -18,8 +18,8 @@ resource "aws_ecs_task_definition" "task" { image = "${local.user_id}.dkr.ecr.${local.region}.amazonaws.com/${local.container_name}:latest" portMappings = [{ - containerPort = 8000 - hostPort = 8000 + containerPort = local.container_port + hostPort = local.container_port protocol = "tcp" }] }]) @@ -46,7 +46,7 @@ resource "aws_ecs_service" "ecs_service" { load_balancer { target_group_arn = module.alb.target_groups["ecs"].arn container_name = local.container_name - container_port = 8000 + container_port = local.container_port } tags = local.tags diff --git a/infra/security_group.tf b/infra/security_group.tf index 89fd03f..61a0027 100644 --- a/infra/security_group.tf +++ b/infra/security_group.tf @@ -25,8 +25,8 @@ resource "aws_security_group" "security_group" { # API ingress { description = "API" - from_port = 8000 - to_port = 8000 + from_port = local.container_port + to_port = local.container_port protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] }