-
Notifications
You must be signed in to change notification settings - Fork 1
/
alb.tf
52 lines (42 loc) · 1.2 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
## ALB
module "alb_sg" {
source = "terraform-aws-modules/security-group/aws//modules/https-443"
version = "~> 4.0"
name = "${var.name}-alb"
description = "Security group for web-server with HTTP ports open within VPC"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
tags = var.tags
}
resource "aws_lb" "alb" {
name = var.name
load_balancer_type = "application"
subnets = module.vpc.public_subnets
security_groups = [module.alb_sg.security_group_id]
idle_timeout = 60
tags = var.tags
}
resource "aws_lb_listener" "https" {
load_balancer_arn = aws_lb.alb.arn
port = "443"
protocol = "HTTPS"
certificate_arn = module.acm.acm_certificate_arn
default_action {
type = "fixed-response"
fixed_response {
content_type = "text/plain"
message_body = "Requests otherwise not routed"
status_code = "200"
}
}
}
resource "aws_route53_record" "api" {
zone_id = data.aws_route53_zone.this.zone_id
name = var.api_url
type = "A"
alias {
name = aws_lb.alb.dns_name
zone_id = aws_lb.alb.zone_id
evaluate_target_health = true
}
}