-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnomad_ui_alb.tf
67 lines (57 loc) · 2 KB
/
nomad_ui_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
## ALB -> ALB-Listener (port 80) -forwards to -> target-group (on port 4646) which is attached to the
## AutoScalingGroup that maintains the nomad-servers.
resource "aws_alb" "alb_nomad_ui" {
name = "${var.stack_name}-nomad-ui${var.unique_postfix}"
internal = false
subnets = var.subnet_ids
security_groups = [aws_security_group.sg_ui_alb.id]
tags = {
Name = "${var.stack_name}-nomad-ui${var.unique_postfix}"
}
}
resource "aws_autoscaling_attachment" "asg_attachment_nomad_ui" {
autoscaling_group_name = var.nomad_server_asg_name
alb_target_group_arn = aws_alb_target_group.tgr_nomad_ui.arn
}
resource "aws_alb_target_group" "tgr_nomad_ui" {
name_prefix = "nomad"
port = var.nomad_ui_port
protocol = "HTTP"
vpc_id = var.vpc_id
health_check {
interval = 15
path = "/ui/jobs"
port = var.nomad_ui_port
protocol = "HTTP"
timeout = 3
healthy_threshold = 2
unhealthy_threshold = 2
}
tags = {
Name = "${var.stack_name}-nomad-ui${var.unique_postfix}"
}
}
# HTTP listener, used when no https certificate is provided.
resource "aws_alb_listener" "alb_http_nomad_ui" {
count = var.ui_alb_use_https_listener ? 0 : 1
load_balancer_arn = aws_alb.alb_nomad_ui.arn
protocol = "HTTP"
port = local.listener_port
default_action {
target_group_arn = aws_alb_target_group.tgr_nomad_ui.arn
type = "forward"
}
}
# HTTPS listener, used when a https certificate is provided.
resource "aws_alb_listener" "albl_https_nomad_ui" {
count = var.ui_alb_use_https_listener ? 1 : 0
load_balancer_arn = aws_alb.alb_nomad_ui.arn
protocol = "HTTPS"
port = local.listener_port
certificate_arn = var.ui_alb_https_listener_cert_arn
ssl_policy = local.ssl_policy
default_action {
target_group_arn = aws_alb_target_group.tgr_nomad_ui.arn
type = "forward"
}
}