-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb.tf
37 lines (32 loc) · 963 Bytes
/
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
# ALB для ASG та його компоненти
resource "aws_lb" "my_lb" {
name = "my-lb"
internal = false
load_balancer_type = "application"
subnets = module.vpc.public_subnets
security_groups = [aws_security_group.nginx.id]
}
resource "aws_lb_target_group" "my_target_group" {
name = "my-tg"
port = 80
protocol = "HTTP"
vpc_id = module.vpc.vpc_id
health_check {
path = "/"
}
}
resource "aws_lb_target_group_attachment" "attach_my_ec2" {
count = length(aws_instance.app.*.id)
target_group_arn = aws_lb_target_group.my_target_group.arn
target_id = aws_instance.app.*.id[count.index]
port = 80
}
resource "aws_lb_listener" "my_listener" {
load_balancer_arn = aws_lb.my_lb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.my_target_group.arn
}
}