-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
53 lines (47 loc) · 1.12 KB
/
main.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
resource "aws_security_group" "alb-sg" {
name = "ALBSecurityGroup"
vpc_id = var.vpc_id
tags = {
Name = "TF_ALBSecurityGroup"
}
ingress {
from_port = 80
protocol = "tcp"
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
protocol = "-1"
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_alb" "app-lb" {
name = "phonebook-lb-tf"
ip_address_type = "ipv4"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb-sg.id]
subnets = var.subnets
}
resource "aws_alb_listener" "app-listener" {
load_balancer_arn = aws_alb.app-lb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_alb_target_group.app-lb-tg.arn
}
}
resource "aws_alb_target_group" "app-lb-tg" {
name = "phonebook-lb-tg"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "instance"
health_check {
healthy_threshold = 2
unhealthy_threshold = 3
}
}