generated from michaeldeggers/repo_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb.tf
101 lines (86 loc) · 2.3 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
resource "aws_lb" "ghost_alb" {
name = "${local.name_prefix}-alb"
load_balancer_type = "application"
security_groups = [aws_security_group.ghost_lb_sg.id]
subnets = [module.vpc.public_subnets[0], module.vpc.public_subnets[1]]
tags = merge(var.additional_tags,
{
"Name" = "${local.name_prefix}-alb"
})
}
resource "aws_lb_listener" "ghost_lb_listener" {
load_balancer_arn = aws_lb.ghost_alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
resource "aws_lb_listener" "ghost_lb_listener_https" {
load_balancer_arn = aws_lb.ghost_alb.arn
port = 443
protocol = "HTTPS"
certificate_arn = data.aws_acm_certificate.amazon_issued.arn
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.ghost_lb_tg.arn
}
}
resource "aws_lb_target_group" "ghost_lb_tg" {
name_prefix = substr("${var.project_name}", 0, 6)
port = 80
protocol = "HTTP"
deregistration_delay = 180
vpc_id = module.vpc.vpc_id
health_check {
healthy_threshold = 3
interval = 10
}
tags = merge(var.additional_tags,
{
"Name" = "${local.name_prefix}-alb"
})
}
resource "aws_security_group" "ghost_lb_sg" {
name = "${local.name_prefix}-sg-alb"
vpc_id = module.vpc.vpc_id
# Accept http traffic from the internet
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# Accept http traffic from the internet
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = merge(var.additional_tags,
{
"Name" = "${local.name_prefix}-alb-sg"
})
}
resource "aws_route53_record" "blog" {
zone_id = data.aws_route53_zone.zone.zone_id
name = "blog.${var.route53_hosted_zone_name}"
type = "A"
alias {
name = aws_lb.ghost_alb.dns_name
zone_id = aws_lb.ghost_alb.zone_id
evaluate_target_health = true
}
}