-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathloadbalancing.tf
More file actions
52 lines (42 loc) · 1.18 KB
/
loadbalancing.tf
File metadata and controls
52 lines (42 loc) · 1.18 KB
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
# file to deploy application load balancer with listeners
# create application load balancer
resource "aws_lb" "webAlb" {
name = var.alb_name
internal = false
load_balancer_type = "application"
security_groups = var.alb_security_group_id
subnets = [var.pub_sub1_id, var.pub_sub2_id]
}
# create target groups
resource "aws_lb_target_group" "albTgHttp" {
name = "HTTP-tg"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
}
resource "aws_lb_target_group_attachment" "httpAttach1" {
target_group_arn = aws_lb_target_group.albTgHttp.arn
target_id = var.web1_id
port = 80
}
resource "aws_lb_target_group_attachment" "httpAttach2" {
target_group_arn = aws_lb_target_group.albTgHttp.arn
target_id = var.web2_id
port = 80
}
# create listeners
resource "aws_lb_listener" "listenerHttp" {
load_balancer_arn = aws_lb.webAlb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.albTgHttp.arn
}
}
output "alb_dns_name" {
value = aws_lb.webAlb.dns_name
}
output "alb_arn" {
value = aws_lb.webAlb.arn
}