forked from covidgreen/covid-green-interoperability-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb.tf
90 lines (77 loc) · 2.57 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
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
# #########################################
# ALB Interop
# #########################################
module "alb_interop_sg" {
source = "./modules/security-group"
open_egress = true
name = "${module.labels.id}-alb-interop"
environment = var.environment
vpc_id = module.vpc.vpc_id
tags = module.labels.tags
}
resource "aws_security_group_rule" "alb_interop_http_ingress" {
description = "Allows connection on port 80 from anywhere"
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = module.alb_interop_sg.id
}
resource "aws_lb" "interop" {
name = "${module.labels.id}-interop"
internal = false
subnets = module.vpc.public_subnets
security_groups = ["${module.alb_interop_sg.id}"]
enable_cross_zone_load_balancing = true
enable_http2 = true
ip_address_type = "dualstack"
enable_deletion_protection = true
tags = module.labels.tags
}
resource "aws_lb_target_group" "interop" {
name = "${module.labels.id}-interop"
port = var.interop_listening_port
protocol = var.interop_listening_protocol
vpc_id = module.vpc.vpc_id
deregistration_delay = "10"
target_type = "ip"
health_check {
path = var.health_check_path
matcher = var.health_check_matcher
interval = var.health_check_interval
timeout = var.health_check_timeout
healthy_threshold = var.health_check_healthy_threshold
unhealthy_threshold = var.health_check_unhealthy_threshold
}
tags = module.labels.tags
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb_listener" "interop_http" {
load_balancer_arn = aws_lb.interop.id
port = 80
protocol = "HTTP"
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "Forbidden"
status_code = "403"
}
}
}
resource "aws_lb_listener_rule" "header_check" {
listener_arn = aws_lb_listener.interop_http.arn
action {
type = "forward"
target_group_arn = aws_lb_target_group.interop.arn
}
condition {
http_header {
http_header_name = "X-Routing-Secret"
values = [jsondecode(data.aws_secretsmanager_secret_version.api_gateway_header.secret_string)["header-secret"]]
}
}
}