generated from devopsacademyau/projects-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
alb.tf
54 lines (47 loc) · 1.32 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
resource "aws_alb" "webapp_alb" {
subnets = var.public_subnets
security_groups = [aws_security_group.alb_sg.id]
}
resource "aws_alb_target_group" "webapp_tg" {
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"
health_check {
interval = 60
path = "/index.html"
port = 80
protocol = "HTTP"
timeout = 30
matcher = "200-302,404"
}
lifecycle {
create_before_destroy = true
}
depends_on = [aws_alb.webapp_alb]
}
# Redirect all traffic from ALB to Target Group
resource "aws_alb_listener" "front_end" {
load_balancer_arn = aws_alb.webapp_alb.id
port = var.app_port_secure
protocol = "HTTPS"
depends_on = [aws_alb_target_group.webapp_tg]
certificate_arn = var.acm_cert_arn
default_action {
target_group_arn = aws_alb_target_group.webapp_tg.id
type = "forward"
}
}
# We are creating route53 hosted zone on the console
# as it is best to have a set of NS records to configure
# our domain name in freenom
resource "aws_route53_record" "wp_route53" {
zone_id = var.hosted_zone_id
name = var.domain_name
type = "A"
alias {
name = aws_alb.webapp_alb.dns_name
zone_id = aws_alb.webapp_alb.zone_id
evaluate_target_health = true
}
}