70 lines
2.0 KiB
HCL
70 lines
2.0 KiB
HCL
# 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,
|
|
aws_security_group.load_balancer_health_check.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" "shockrah_xyz" {
|
|
name = "${var.athens_prefix}-shockrah-xyz"
|
|
port = var.nginx_port
|
|
protocol = "HTTP"
|
|
target_type = "ip"
|
|
vpc_id = aws_vpc.athens_vpc.id
|
|
health_check {
|
|
interval = 60
|
|
}
|
|
}
|
|
|
|
resource "aws_lb_listener" "http" {
|
|
load_balancer_arn = aws_lb.alpha.arn
|
|
port = 80
|
|
protocol = "HTTP"
|
|
default_action {
|
|
type = "redirect"
|
|
|
|
redirect {
|
|
port = 443
|
|
protocol = "HTTPS"
|
|
status_code = "HTTP_301"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "aws_lb_listener" "https" {
|
|
load_balancer_arn = aws_lb.alpha.arn
|
|
port = 443
|
|
protocol = "HTTPS"
|
|
ssl_policy = "ELBSecurityPolicy-2016-08"
|
|
|
|
certificate_arn = aws_acm_certificate_validation.shockrah_xyz.certificate_arn
|
|
default_action {
|
|
type = "forward"
|
|
target_group_arn = aws_lb_target_group.shockrah_xyz.arn
|
|
}
|
|
}
|
|
|
|
# Certificate attachment for project athens
|
|
###########################################
|
|
# Additional certificate for the .net
|
|
resource "aws_lb_listener_certificate" "alpha_project_athens_cert" {
|
|
listener_arn = aws_lb_listener.https.arn
|
|
certificate_arn = aws_acm_certificate_validation.project_athens_xyz.certificate_arn
|
|
}
|
|
|