-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathapplication-load-balancer.tf
52 lines (44 loc) · 1.56 KB
/
application-load-balancer.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
resource "aws_alb" "film_ratings_alb_load_balancer" {
name = "film-ratings-alb-load-balancer"
security_groups = ["${aws_security_group.film_ratings_public_sg.id}"]
subnets = ["${aws_subnet.film_ratings_public_sn_01.id}", "${aws_subnet.film_ratings_public_sn_02.id}"]
tags = {
Name = "film-ratings-alb-load-balancer"
}
}
resource "aws_alb_target_group" "film_ratings_app_target_group" {
name = "film-ratings-app-target-group"
port = 3000
protocol = "HTTP"
vpc_id = "${aws_vpc.film_ratings_vpc.id}"
deregistration_delay = "10"
health_check {
healthy_threshold = "2"
unhealthy_threshold = "6"
interval = "30"
matcher = "200,301,302"
path = "/"
protocol = "HTTP"
timeout = "5"
}
stickiness {
type = "lb_cookie"
}
tags = {
Name = "film-ratings-app-target-group"
}
}
resource "aws_alb_listener" "alb-listener" {
load_balancer_arn = "${aws_alb.film_ratings_alb_load_balancer.arn}"
port = "80"
protocol = "HTTP"
default_action {
target_group_arn = "${aws_alb_target_group.film_ratings_app_target_group.arn}"
type = "forward"
}
}
resource "aws_autoscaling_attachment" "asg_attachment_film_rating_app" {
autoscaling_group_name = "film-ratings-autoscaling-group"
alb_target_group_arn = "${aws_alb_target_group.film_ratings_app_target_group.arn}"
depends_on = [ "aws_autoscaling_group.film-ratings-autoscaling-group" ]
}