-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05-lb.tf
59 lines (46 loc) · 1.28 KB
/
05-lb.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
resource "aws_lb" "app1_lb" {
name = "app1-test-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.instances_app1_security_group.id]
subnets = ["subnet-" , "subnet-"]
}
resource "aws_lb_listener" "app1_lb_listner-443" {
load_balancer_arn = aws_lb.app1_lb.arn
protocol = "HTTP"
port = 443
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.app1-instances.arn
}
}
resource "aws_lb_listener" "app1_lb_listner-80" {
load_balancer_arn = aws_lb.app1_lb.arn
protocol = "HTTP"
port = 80
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.app1-instances.arn
}
}
resource "aws_lb_target_group" "app1-instances" {
name = "app1-instances"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
health_check {
enabled = true
path = "/index.html"
matcher = "200-299"
healthy_threshold = 2
unhealthy_threshold = 2
interval = 15
port = 80
timeout = 10
}
}
resource "aws_lb_target_group_attachment" "lb_instance_attachments" {
count = length(aws_instance.t4gnano_instance)
target_id = aws_instance.t4gnano_instance[count.index].id
target_group_arn = aws_lb_target_group.app1-instances.arn
}