-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb.tf
42 lines (37 loc) · 1.28 KB
/
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
resource "aws_lb" "terraform-lab" {
name = "${var.ec2_instance_name}-alb"
load_balancer_type = "application"
internal = false
security_groups = [aws_security_group.load-balancer.id]
subnets = [aws_subnet.public-subnet-1.id, aws_subnet.public-subnet-2.id] #
}
# Target group
resource "aws_alb_target_group" "default-target-group" {
name = "${var.ec2_instance_name}-tg"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.terraform-lab-vpc.id
health_check {
path = var.health_check_path
port = "traffic-port"
healthy_threshold = 5
unhealthy_threshold = 2
timeout = 2
interval = 60
matcher = "200"
}
}
resource "aws_autoscaling_attachment" "asg_attachment_bar" {
autoscaling_group_name = aws_autoscaling_group.ec2-cluster.id
lb_target_group_arn = aws_alb_target_group.default-target-group.arn
}
resource "aws_alb_listener" "ec2-alb-http-listener" {
load_balancer_arn = aws_lb.terraform-lab.id
port = "80"
protocol = "HTTP"
depends_on = [aws_alb_target_group.default-target-group]
default_action {
type = "forward"
target_group_arn = aws_alb_target_group.default-target-group.arn
}
}