-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelb.tf
63 lines (56 loc) · 1.8 KB
/
elb.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
# ---------------------------------------------
# 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
]
}
# ---------------------------------------------
# listener
# ---------------------------------------------
resource "aws_lb_listener" "aws_listener_http" {
load_balancer_arn = aws_lb.alb.arn
port = var.http_port
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.alb_target_group.arn
}
}
resource "aws_lb_listener" "aws_listener_https" {
load_balancer_arn = aws_lb.alb.arn
port = var.https_port
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
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 = var.app_port
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
# }