diff --git a/create-an-aws-ecs-byoc-app/components/ecs-service/alb.tf b/create-an-aws-ecs-byoc-app/components/ecs-service/alb.tf index e0aa4f7..8d7817b 100644 --- a/create-an-aws-ecs-byoc-app/components/ecs-service/alb.tf +++ b/create-an-aws-ecs-byoc-app/components/ecs-service/alb.tf @@ -52,11 +52,14 @@ module "ingress" { target_groups = { api = { - name_prefix = "api-" + name_prefix = "api" protocol = "HTTP" - port = 8080 + backend_port = var.container_port target_type = "ip" create_attachment = false + deregistration_delay = 5 + load_balancing_cross_zone_enabled = true + health_check = { enabled = true interval = 10 diff --git a/create-an-aws-ecs-byoc-app/components/ecs-service/service.tf b/create-an-aws-ecs-byoc-app/components/ecs-service/service.tf index e75e137..d948a1f 100644 --- a/create-an-aws-ecs-byoc-app/components/ecs-service/service.tf +++ b/create-an-aws-ecs-byoc-app/components/ecs-service/service.tf @@ -4,6 +4,7 @@ module "service" { name = var.service_name cluster_arn = var.cluster_arn + desired_count = 3 cpu = 1024 memory = 4096 @@ -43,7 +44,7 @@ module "service" { service = { target_group_arn = module.ingress.target_groups["api"].arn container_name = "api" - container_port = 8080 + container_port = var.container_port } } @@ -51,8 +52,8 @@ module "service" { security_group_rules = { ingress_http = { type = "ingress" - from_port = 0 - to_port = 0 + from_port = var.container_port + to_port = var.container_port protocol = "tcp" description = "Service port" source_security_group_id = module.ingress.security_group_id diff --git a/create-an-aws-ecs-byoc-app/components/ecs-service/variables.tf b/create-an-aws-ecs-byoc-app/components/ecs-service/variables.tf index b19227b..f0c56b2 100644 --- a/create-an-aws-ecs-byoc-app/components/ecs-service/variables.tf +++ b/create-an-aws-ecs-byoc-app/components/ecs-service/variables.tf @@ -1,4 +1,7 @@ # Service config +variable "container_port" { + default = 8080 +} variable "service_name" { type = string