-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalb.tf
68 lines (60 loc) · 1.49 KB
/
alb.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
# -- ALB --
# Creates ALB SG
resource "aws_security_group" "alb" {
name = "alb_security_group"
description = "ALB Security Group"
vpc_id = aws_vpc.vpc.id
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = var.allowed_alb_cidr_blocks
}
# Allow all outbound traffic.
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "alb-security-group"
}
}
# Creates ALB on Public Subnet
resource "aws_alb" "alb" {
name = "app-lb"
security_groups = [aws_security_group.alb.id]
subnets = aws_subnet.public.*.id
tags = {
Name = "app-lb-servian"
}
}
# Create new target group for ALB
resource "aws_alb_target_group" "group" {
name = "alb-tgt-grp"
port = 3000
protocol = "HTTP"
vpc_id = aws_vpc.vpc.id
stickiness {
type = "lb_cookie" # Defines stickiness, but not needed for now since DB is queried from backend
}
# Alter the destination of the health check
health_check {
path = "/"
port = 3000
}
tags = {
Name = "alb-target-group"
}
}
# Create listener for port 80 - HTTP traffic
resource "aws_alb_listener" "listener_http" {
load_balancer_arn = aws_alb.alb.arn
port = "80"
protocol = "HTTP"
default_action {
target_group_arn = aws_alb_target_group.group.arn
type = "forward"
}
}