-
Notifications
You must be signed in to change notification settings - Fork 0
/
lb.tf
87 lines (72 loc) · 2.1 KB
/
lb.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
resource "aws_lb_target_group" "my-target-group" {
health_check {
interval = 10
path = "/"
protocol = "HTTP"
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
name = "my-test-tg"
port = 80
protocol = "HTTP"
target_type = "instance"
vpc_id = "${aws_vpc.main.id}"
}
resource "aws_lb" "my-aws-alb" {
name = "my-test-alb"
internal = false
security_groups = [
"${aws_security_group.my-alb-sg.id}",
]
subnets = "${aws_subnet.public_subnet.*.id}"
tags = {
Name = "my-test-alb"
}
ip_address_type = "ipv4"
load_balancer_type = "application"
}
resource "aws_lb_listener" "my-test-alb-listner" {
load_balancer_arn = "${aws_lb.my-aws-alb.arn}"
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = "${aws_lb_target_group.my-target-group.arn}"
}
}
resource "aws_security_group" "my-alb-sg" {
name = "my-alb-sg"
# vpc_id = "${var.vpc_id}"
vpc_id = "${aws_vpc.main.id}"
}
resource "aws_security_group_rule" "inbound_ssh" {
from_port = 22
protocol = "tcp"
security_group_id = "${aws_security_group.my-alb-sg.id}"
to_port = 22
type = "ingress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "inbound_http" {
from_port = 80
protocol = "tcp"
security_group_id = "${aws_security_group.my-alb-sg.id}"
to_port = 80
type = "ingress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "outbound_all" {
from_port = 0
protocol = "-1"
security_group_id = "${aws_security_group.my-alb-sg.id}"
to_port = 0
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_lb_target_group_attachment" "attach" {
target_group_arn = "${aws_lb_target_group.my-target-group.arn}"
count = length(aws_instance.my-test-instance)
target_id = aws_instance.my-test-instance[count.index].id
port = 80
}