-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
105 lines (86 loc) · 2.91 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
95
96
97
98
99
100
101
102
103
104
105
module "alb" {
providers = { aws = aws.alb }
source = "./modules/alb"
description = var.description
name = var.name
security_group_name = var.security_group_name
subnet_ids = var.subnet_ids
tags = var.tags
vpc_id = var.vpc_id
}
module "cloudwatch_alarms" {
providers = { aws = aws.alb }
source = "./modules/alb-cloudwatch-alarms"
alarm_actions = var.alarm_actions
alarm_evaluation_minutes = var.alarm_evaluation_minutes
alb = module.alb.instance
failure_threshold = var.failure_threshold
slow_response_threshold = var.slow_response_threshold
target_groups = local.target_groups
}
module "http" {
providers = { aws = aws.alb }
source = "./modules/alb-http-redirect"
alb = module.alb.instance
}
module "https" {
providers = { aws = aws.alb }
source = "./modules/alb-https-forward"
alb = module.alb.instance
alternative_domain_names = local.alternative_certificate_domains
certificate_domain_name = var.primary_certificate_domain
certificate_types = var.certificate_types
target_groups = local.target_groups
target_group_weights = var.target_group_weights
depends_on = [module.acm_certificate]
}
module "acm_certificate" {
for_each = toset(var.issue_certificate_domains)
providers = { aws.certificate = aws.alb, aws.route53 = aws.route53 }
source = "./modules/acm-certificate"
allow_overwrite = var.allow_overwrite
domain_name = each.value
hosted_zone_name = var.validate_certificates ? var.hosted_zone_name : null
}
module "alias" {
for_each = toset(var.create_domain_aliases)
providers = { aws = aws.route53 }
source = "./modules/alb-route53-alias"
alb_dns_name = module.alb.dns_name
alb_zone_id = module.alb.zone_id
allow_overwrite = var.allow_overwrite
hosted_zone_name = var.hosted_zone_name
name = each.value
}
module "target_group" {
for_each = var.target_groups
providers = { aws = aws.alb }
source = "./modules/alb-target-group"
enable_stickiness = var.enable_stickiness
health_check_path = each.value.health_check_path
health_check_port = each.value.health_check_port
name = each.value.name
vpc_id = var.vpc_id
}
data "aws_lb_target_group" "legacy" {
for_each = toset(var.legacy_target_group_names)
name = each.value
}
locals {
certificate_domains = toset(concat(
[var.primary_certificate_domain],
var.issue_certificate_domains,
var.attach_certificate_domains
))
alternative_certificate_domains = setsubtract(
local.certificate_domains,
[var.primary_certificate_domain]
)
target_groups = zipmap(
concat(keys(var.target_groups), keys(data.aws_lb_target_group.legacy)),
concat(
values(module.target_group).*.instance,
values(data.aws_lb_target_group.legacy)
)
)
}