-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelb.tf
More file actions
52 lines (48 loc) · 1.73 KB
/
elb.tf
File metadata and controls
52 lines (48 loc) · 1.73 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
# -----------------------------------------------------------------------------
# ALB
# -----------------------------------------------------------------------------
resource "aws_lb" "alb" {
name = "${var.project}-${var.environment}-app-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.web_sg.id]
subnets = [aws_subnet.public_subnet_1a.id, aws_subnet.public_subnet_1c.id]
}
resource "aws_lb_listener" "alb_listener_http" {
load_balancer_arn = aws_lb.alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.alb_target_group.arn
}
}
resource "aws_lb_listener" "alb_listener_https" {
load_balancer_arn = aws_lb.alb.arn
port = 443
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-TLS13-1-2-2021-06"
certificate_arn = aws_acm_certificate.tokyo_cert.arn
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.alb_target_group.arn
}
}
# -----------------------------------------------------------------------------
# Target Group
# -----------------------------------------------------------------------------
resource "aws_lb_target_group" "alb_target_group" {
name = "${var.project}-${var.environment}-app-tg"
port = 3000
protocol = "HTTP"
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.project}-${var.environment}-app-tg"
Project = var.project
Env = var.environment
}
}
# resource "aws_lb_target_group_attachment" "instance" {
# target_group_arn = aws_lb_target_group.alb_target_group.arn
# target_id = aws_instance.app_server.id
# }