resource "aws_lb" "alsi-master-alb" { # checkov:skip=CKV_AWS_150: Skip deletion protection - Test env name = "${var.prefix}-alsi-master-alb" internal = true load_balancer_type = "application" drop_invalid_header_fields = true security_groups = [aws_security_group.alsi-master-alb-sg.id] # Note, changing subnets results in recreation of the resource subnets = var.subnets enable_cross_zone_load_balancing = true access_logs { bucket = "xdr-elb-${var.environment}" enabled = true } tags = merge(local.standard_tags, var.tags) } ######################### # Listeners resource "aws_lb_listener" "alsi-master-alb-listener-https" { load_balancer_arn = aws_lb.alsi-master-alb.arn port = "443" protocol = "HTTPS" ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy certificate_arn = aws_acm_certificate.cert_master.arn default_action { type = "forward" target_group_arn = aws_lb_target_group.alsi-master-alb-target-9000.arn } } # Only alb's can redirect resource "aws_lb_listener" "alsi-master-alb-listener-http" { load_balancer_arn = aws_lb.alsi-master-alb.arn port = "80" protocol = "HTTP" default_action { type = "redirect" redirect { port = "443" protocol = "HTTPS" status_code = "HTTP_301" } } } ######################### # Targets resource "aws_lb_target_group" "alsi-master-alb-target-9000" { name = "${var.prefix}-alsi-master-9000" port = 9000 protocol = "HTTPS" target_type = "instance" vpc_id = var.vpc_id tags = merge(local.standard_tags, var.tags) health_check { enabled = true path = "/api/v1/health" port = 9000 protocol = "HTTPS" } } resource "aws_lb_target_group_attachment" "alsi-master-alb-target-9000-instance" { target_group_arn = aws_lb_target_group.alsi-master-alb-target-9000.arn target_id = aws_instance.master.id port = 9000 } #---------------------------------------------------------------------------- # Security Group for ALB #---------------------------------------------------------------------------- resource "aws_security_group" "alsi-master-alb-sg" { name_prefix = "${var.prefix}-alsi-master-alb-sg" lifecycle { create_before_destroy = true } # handle updates gracefully description = "Security Group for the Cribl ALB" vpc_id = var.vpc_id tags = merge(local.standard_tags, var.tags) } #---------------------------------------------------------------------------- # INGRESS #---------------------------------------------------------------------------- resource "aws_security_group_rule" "alsi-master-alb-https-in" { type = "ingress" description = "HTTPS - Inbound" from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = local.cidr_map["vpc-access"] security_group_id = aws_security_group.alsi-master-alb-sg.id } resource "aws_security_group_rule" "alsi-master-http-in" { # Port 80 is open as a redirect to 443 type = "ingress" description = "HTTP redirect HTTPS - Inbound" from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = local.cidr_map["vpc-access"] security_group_id = aws_security_group.alsi-master-alb-sg.id } #---------------------------------------------------------------------------- # EGRESS #---------------------------------------------------------------------------- resource "aws_security_group_rule" "alsi-master-alb-9000-out" { type = "egress" description = "9000 - Outbound" from_port = 9000 to_port = 9000 protocol = "tcp" source_security_group_id = aws_security_group.alsi_master_security_group.id security_group_id = aws_security_group.alsi-master-alb-sg.id } #---------------------------------------------------------------------------- # DNS Entry #---------------------------------------------------------------------------- resource "aws_route53_record" "alsi_master_alb" { zone_id = var.dns_info["private"]["zone_id"] name = "${var.prefix}-alsi" type = "CNAME" records = [aws_lb.alsi-master-alb.dns_name] ttl = "60" provider = aws.c2 }