Hooking service to a load balancer
This commit is contained in:
parent
6212a7d8cc
commit
d4dae7618b
@ -121,6 +121,12 @@ resource "aws_ecs_service" "sample" {
|
|||||||
task_definition = aws_ecs_task_definition.sample.arn
|
task_definition = aws_ecs_task_definition.sample.arn
|
||||||
desired_count = 1
|
desired_count = 1
|
||||||
launch_type = "FARGATE"
|
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 {
|
network_configuration {
|
||||||
assign_public_ip = true
|
assign_public_ip = true
|
||||||
subnets = [ local.subnet ]
|
subnets = [ local.subnet ]
|
||||||
|
36
infra/load-balancer.tf
Normal file
36
infra/load-balancer.tf
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user