-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnginx-alb.tf
49 lines (43 loc) · 1.25 KB
/
nginx-alb.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Define Application Load Balancer - alb.tf
resource "aws_alb" "main" {
name = "${var.nginx_app_name}-load-balancer"
subnets = aws_subnet.aws-subnet.*.id
security_groups = [aws_security_group.aws-lb.id]
tags = {
Name = "${var.app_name}-alb"
}
}
resource "aws_alb_target_group" "nginx_app" {
name = "${var.nginx_app_name}-target-group"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.aws-vpc.id
target_type = "ip"
health_check {
healthy_threshold = "3"
interval = "30"
protocol = "HTTP"
matcher = "200"
timeout = "3"
path = "/"
unhealthy_threshold = "2"
}
tags = {
Name = "${var.nginx_app_name}-alb-target-group"
}
}
# Redirect all traffic from the ALB to the target group
resource "aws_alb_listener" "front_end" {
load_balancer_arn = aws_alb.main.id
port = var.nginx_app_port
protocol = "HTTP"
default_action {
target_group_arn = aws_alb_target_group.nginx_app.id
type = "forward"
}
}
# output nginx public ip
output "nginx_dns_lb" {
description = "DNS load balancer"
value = aws_alb.main.dns_name
}