diff --git a/alb.tf b/alb.tf index 3b8f908..ce7ae54 100644 --- a/alb.tf +++ b/alb.tf @@ -33,7 +33,7 @@ resource "aws_lb_target_group" "nginx_tg" { port = 80 protocol = "HTTP" vpc_id = aws_vpc.main.id - target_type = "ip" + target_type = "instance" } resource "aws_lb_listener" "nginx_listener" { diff --git a/ec2.tf b/ec2.tf index c505cab..d647dcc 100644 --- a/ec2.tf +++ b/ec2.tf @@ -39,6 +39,13 @@ resource "aws_security_group" "ecs_instance_sg" { name_prefix = "ecs-instance-sg-" vpc_id = aws_vpc.main.id + ingress { + from_port = 32768 + to_port = 60999 + protocol = "tcp" + security_groups = [aws_security_group.nginx_sg.id] + } + egress { from_port = 0 to_port = 0 diff --git a/ecs.tf b/ecs.tf index c343f52..ecf8b87 100644 --- a/ecs.tf +++ b/ecs.tf @@ -21,7 +21,7 @@ resource "aws_iam_role" "ecs_task_exec" { resource "aws_ecs_task_definition" "nginx_task" { family = "nginx_task" - network_mode = "awsvpc" + network_mode = "bridge" execution_role_arn = aws_iam_role.ecs_task_exec.arn requires_compatibilities = ["EC2"] cpu = "256" @@ -34,7 +34,7 @@ resource "aws_ecs_task_definition" "nginx_task" { portMappings = [ { containerPort = 80 - hostPort = 80 + hostPort = 0 } ] logConfiguration = { @@ -72,13 +72,9 @@ resource "aws_ecs_service" "nginx_service" { name = "nginx_service" cluster = aws_ecs_cluster.main.id task_definition = aws_ecs_task_definition.nginx_task.arn - desired_count = 2 + desired_count = 3 launch_type = "EC2" - network_configuration { - subnets = [aws_subnet.sub.id] - security_groups = [aws_security_group.ecs_http_sg.id] - } - depends_on = [aws_lb_target_group.nginx_tg] + depends_on = [aws_lb_target_group.nginx_tg] load_balancer { target_group_arn = aws_lb_target_group.nginx_tg.arn container_name = "nginx"