-
Notifications
You must be signed in to change notification settings - Fork 7
/
load-balancer.tf
81 lines (65 loc) · 1.68 KB
/
load-balancer.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
# =============================================
# ALB
# =============================================
resource "aws_security_group" "alb" {
name_prefix = "${var.cluster_name}-lb"
vpc_id = var.vpc_id
tags = local.common_tags
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb" "this" {
name_prefix = "${var.cluster_name}-lb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = var.public_subnets
enable_deletion_protection = false
tags = local.common_tags
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb_target_group" "awx" {
name_prefix = substr("${var.cluster_name}-tgtgrp", 0, 6)
port = 8052
protocol = "HTTP"
target_type = "ip"
vpc_id = var.vpc_id
lifecycle {
create_before_destroy = true
}
health_check {
interval = 10
timeout = 5
path = "/"
healthy_threshold = 2
unhealthy_threshold = 2
}
tags = local.common_tags
}
resource "aws_lb_listener" "awx" {
load_balancer_arn = aws_lb.this.arn
port = 443
protocol = "HTTPS"
certificate_arn = var.alb_ssl_certificate_arn
depends_on = [aws_lb_target_group.awx]
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.awx.arn
}
}
resource "aws_lb_listener" "https_redirect" {
load_balancer_arn = aws_lb.this.arn
port = 80
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}