-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewelb.tf
78 lines (69 loc) · 2.01 KB
/
newelb.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
resource "aws_lb_target_group" "blue" {
name = "blue-tg-lb"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.main.id
health_check {
port = 80
protocol = "HTTP"
timeout = 5
interval = 10
}
}
resource "aws_lb_target_group_attachment" "blue" {
count = length(aws_instance.alex-instance)
target_group_arn = aws_lb_target_group.blue.arn
target_id = aws_instance.alex-instance[count.index].id
port = 80
depends_on = [aws_instance.alex-instance]
}
resource "aws_lb_target_group" "green" {
name = "green-tg-lb"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.main.id
health_check {
port = 80
protocol = "HTTP"
timeout = 5
interval = 10
}
}
resource "aws_lb_target_group_attachment" "green" {
count = length(aws_instance.alex-instance2)
target_group_arn = aws_lb_target_group.green.arn
target_id = aws_instance.alex-instance2[count.index].id
port = 80
depends_on = [aws_instance.alex-instance2]
}
resource "aws_lb" "alex-applb" {
name = "main-app-lb"
internal = false
load_balancer_type = "application"
subnets = [for subnet in aws_subnet.main-public-1 : subnet.id]
security_groups = [aws_security_group.allow-ssh.id]
depends_on = [aws_instance.alex-instance]
}
resource "aws_lb_listener" "alex-applb-listener" {
load_balancer_arn = aws_lb.alex-applb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
# target_group_arn = aws_lb_target_group.blue.arn
forward {
target_group {
arn = aws_lb_target_group.blue.arn
weight = lookup(local.traffic_dist_map[var.traffic_distribution], "blue", 100)
}
target_group {
arn = aws_lb_target_group.green.arn
weight = lookup(local.traffic_dist_map[var.traffic_distribution], "green", 0)
}
stickiness {
enabled = false
duration = 1
}
}
}
}