-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
95 lines (82 loc) · 3.17 KB
/
main.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
module "default_backend_ecs_service" {
source = "./modules/deprecated"
name = format("%s-%s-404", var.env, var.component)
vpc_id = var.platform_config["vpc"]
}
module "alb" {
source = "./modules/alb"
name = "${replace(
replace(
format("%s-%s", var.env, var.component),
"/(.{0,25}).*/",
"$1",
),
"/^-+|-+$/",
"",
)}-router"
vpc_id = var.platform_config["vpc"]
subnet_ids = split(",", var.platform_config["public_subnets"])
extra_security_groups = [var.platform_config["ecs_cluster.${var.ecs_cluster}.client_security_group"]]
internal = "false"
certificate_domain_name = var.dev_subdomain ? format("*.%s%s", var.env != "live" ? "dev." : "", var.alb_domain) : "*.${var.alb_domain}"
default_target_group_arn = aws_alb_target_group.default_target_group.arn
access_logs_bucket = lookup(var.platform_config, "elb_access_logs_bucket", "")
access_logs_enabled = lookup(var.platform_config, "elb_access_logs_bucket", "") == "" ? false : true
idle_timeout = var.idle_timeout
run_data = var.run_data
tags = {
component = var.component
environment = var.env
team = var.team
}
}
module "dns_record" {
source = "./modules/route53-dns"
domain = var.alb_domain
name = var.component
env = var.env
target = module.alb.alb_dns_name
alb_zone_id = module.alb.alb_zone_id
alias = var.alias
dev_subdomain = var.dev_subdomain
zone_id = var.run_data ? "" : "TESTZONEID"
}
locals {
default_target_group_component = var.default_target_group_component != "" ? var.default_target_group_component : "${var.component}-default-target-group"
}
resource "aws_alb_target_group" "default_target_group" {
name = replace(
replace("${var.env}-default-${var.component}", "/(.{0,32}).*/", "$1"),
"/^-+|-+$/",
"",
)
# port will be set dynamically, but for some reason AWS requires a value
port = "31337"
protocol = "HTTP"
vpc_id = var.platform_config["vpc"]
deregistration_delay = var.default_target_group_deregistration_delay
target_type = var.default_target_group_target_type
health_check {
interval = var.default_target_group_health_check_interval
path = var.default_target_group_health_check_path
timeout = var.default_target_group_health_check_timeout
healthy_threshold = var.default_target_group_health_check_healthy_threshold
unhealthy_threshold = var.default_target_group_health_check_unhealthy_threshold
matcher = var.default_target_group_health_check_matcher
}
tags = {
component = local.default_target_group_component
environment = var.env
service = "${var.env}-${local.default_target_group_component}"
team = var.team
}
dynamic "stickiness" {
for_each = var.sticky
content {
cookie_duration = stickiness.value["cookie_duration"]
cookie_name = stickiness.value["cookie_name"]
enabled = stickiness.value["enabled"]
type = stickiness.value["type"]
}
}
}