-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalb.tf
59 lines (51 loc) · 1.67 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
55
56
57
58
59
# Create a new network load balancer internal
resource "aws_lb" "this" {
name = local.lb_name
internal = var.is_lb_internal
load_balancer_type = "network"
subnets = var.alb_subnet_ids
enable_cross_zone_load_balancing = true
enable_deletion_protection = false
security_groups = concat(var.additional_sg_lb_ids, aws_security_group.lb.id)
tags = merge(var.default_tags, {
Account = local.account_alias
Name = local.lb_name
})
}
# Create Target groups
resource "aws_lb_target_group" "this" {
for_each = local.rabbit_service_ports
name = "tg-${local.lb_name}-${each.key}"
port = each.value.port
protocol = "TCP"
vpc_id = local.vpc_id
health_check {
enabled = true
protocol = "TCP"
}
}
# Create Listeners
resource "aws_alb_listener" "this" {
for_each = local.nlb_listener_ports
load_balancer_arn = aws_lb.this.arn
port = each.value.port
protocol = each.value.secure ? "TLS" : "TCP"
certificate_arn = each.value.certificate_arn
ssl_policy = each.value.ssl_policy
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.this[each.value.service_port].arn
}
depends_on = [aws_lb_target_group.this]
}
resource "aws_route53_record" "internal_cname" {
provider = aws.route53_account
zone_id = data.aws_route53_zone.hosted_zone.id
name = "${var.name}.${var.domain_name}"
type = "A"
alias {
name = aws_lb.this.dns_name
zone_id = aws_lb.this.zone_id
evaluate_target_health = true
}
}