You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
1.0 KiB

resource "aws_lb_target_group" "api_lb_target" {
name = "my-api"
port = 3000
protocol = "HTTP"
target_type = "ip"
vpc_id = aws_vpc.app_vpc.id
health_check {
enabled = true
path = "/health"
}
depends_on = [aws_alb.api_lb]
}
resource "aws_alb" "api_lb" {
name = "${var.project}-api-lb"
internal = false
load_balancer_type = "application"
subnets = [for s in aws_subnet.public_subnet : s.id]
security_groups = [
aws_security_group.http.id,
aws_security_group.https.id,
aws_security_group.egress_all.id,
aws_security_group.ingress_api.id,
]
depends_on = [aws_internet_gateway.igw]
}
resource "aws_alb_listener" "api_http_listener" {
load_balancer_arn = aws_alb.api_lb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.api_lb_target.arn
}
}
output "alb_url" {
value = "http://${aws_alb.api_lb.dns_name}"
}