-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadbalancer.tf
53 lines (48 loc) · 1.6 KB
/
loadbalancer.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
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group
resource "aws_lb_target_group" "front" {
name = "${var.name}-front"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.this.id
health_check {
enabled = true
healthy_threshold = 3
interval = 10
matcher = 200
path = "/"
port = "traffic-port"
protocol = "HTTP"
timeout = 3
unhealthy_threshold = 2
}
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_attachment
resource "aws_autoscaling_attachment" "attach-app" {
autoscaling_group_name = aws_autoscaling_group.application.id
lb_target_group_arn = aws_lb_target_group.front.arn
lifecycle {
create_before_destroy = true
}
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.front.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.front.arn
}
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb
resource "aws_lb" "front" {
name = var.name
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.asg_lb_security_group.id]
subnets = [for subnet in aws_subnet.public : subnet.id]
enable_deletion_protection = false
tags = {
Environment = "Development"
}
}