diff --git a/infra/alpha.tf b/infra/alpha.tf index 2745f4c..ff7cfa7 100644 --- a/infra/alpha.tf +++ b/infra/alpha.tf @@ -121,6 +121,12 @@ resource "aws_ecs_service" "sample" { task_definition = aws_ecs_task_definition.sample.arn desired_count = 1 launch_type = "FARGATE" + load_balancer { + target_group_arn = aws_lb_target_group.alpha_cluster.arn + container_name = "${var.athens_prefix}-sample-container" + container_port = 8080 + } + network_configuration { assign_public_ip = true subnets = [ local.subnet ] diff --git a/infra/load-balancer.tf b/infra/load-balancer.tf new file mode 100644 index 0000000..b5ea059 --- /dev/null +++ b/infra/load-balancer.tf @@ -0,0 +1,36 @@ +# Here is the application load balancer that we use for services hosted on ECS +############################################################################## + + +# The LB that we'll use to move traffic into our services +######################################################### +resource "aws_lb" "alpha" { + name = "alpha-lb" + internal = false + load_balancer_type = "application" + subnets = [ aws_subnet.delphi.id, aws_subnet.crete_subnet.id ] + security_groups = [ aws_security_group.ecs_web_ingress.id ] + # TODO: change this to true later + enable_deletion_protection = false +} + +# ECS services manage themselves when it comes to registering to the +# target group so we only need to provide the pool +#################################################################### +resource "aws_lb_target_group" "alpha_cluster" { + name = "${var.athens_prefix}-alpha-cluster" + port = 80 + protocol = "HTTP" + target_type = "ip" + vpc_id = aws_vpc.athens_vpc.id +} + +resource "aws_lb_listener" "http" { + load_balancer_arn = aws_lb.alpha.arn + port = 80 + protocol = "HTTP" + default_action { + type = "forward" + target_group_arn = aws_lb_target_group.alpha_cluster.arn + } +}