-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalb.tf
More file actions
65 lines (55 loc) · 1.68 KB
/
alb.tf
File metadata and controls
65 lines (55 loc) · 1.68 KB
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
resource "aws_lb_target_group" "flex_gateway" {
name = "${var.app_name}-${var.env_name}-flex-gateway"
port = 8081
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "instance"
# Flex gateway may have relatively long outstanding requests so lets use the full 5 minutes
deregistration_delay = 300
health_check {
enabled = true
port = 80
path = "/custom-health-check.html"
}
}
resource "aws_autoscaling_attachment" "main" {
autoscaling_group_name = aws_autoscaling_group.main.id
lb_target_group_arn = aws_lb_target_group.flex_gateway.arn
}
resource "aws_lb" "main" {
name = "${var.app_name}-${var.env_name}"
internal = false
load_balancer_type = "application"
subnets = var.alb_subnet_ids
security_groups = [aws_security_group.alb.id]
enable_deletion_protection = !var.dev_mode
tags = local.default_tags
}
resource "aws_wafv2_web_acl_association" "main" {
resource_arn = aws_lb.main.arn
web_acl_arn = aws_wafv2_web_acl.main.arn
}
resource "aws_lb_listener" "http" {
load_balancer_arn = aws_lb.main.arn
port = "80"
protocol = "HTTP"
default_action {
type = "redirect"
redirect {
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
}
}
}
resource "aws_lb_listener" "https" {
load_balancer_arn = aws_lb.main.arn
port = "443"
protocol = "HTTPS"
certificate_arn = var.acm_cert_arn
ssl_policy = "ELBSecurityPolicy-TLS13-1-2-Res-2021-06"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.flex_gateway.arn
}
}