123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #----------------------------------------------------------------------------
- # EXTERNAL APPLICATION LB
- #----------------------------------------------------------------------------
- resource "aws_alb" "internal" {
- name = "${var.instance_name}-alb-internal-${var.environment}"
- security_groups = [aws_security_group.alb_server_internal.id]
- internal = true
- subnets = var.subnets
- load_balancer_type = "application"
- drop_invalid_header_fields = true
- access_logs {
- bucket = "xdr-elb-${var.environment}"
- enabled = true
- }
- tags = merge(local.standard_tags, var.tags, { Name = "${var.instance_name}-alb-internal-${var.environment}" })
- }
- # Create a new target group
- resource "aws_alb_target_group" "internal" {
- # use name_prefix instead of name and create-before-destroy on security groups and alb target groups to make future changes easier,
- # otherwise, you get stuck in `destroying` during routine changes.
- name_prefix = substr(var.instance_name, 0, 6)
- port = 3080
- protocol = "HTTPS"
- #deregistration_delay = "${local.lb_deregistration_delay}"
- vpc_id = var.vpc_id
- health_check {
- protocol = "HTTPS"
- port = "3080"
- path = "/web/login"
- matcher = "200-400"
- timeout = "4"
- interval = "5"
- }
- stickiness {
- type = "lb_cookie"
- enabled = true
- }
- tags = merge(local.standard_tags, var.tags)
- lifecycle {
- create_before_destroy = true
- }
- }
- resource "aws_lb_target_group_attachment" "internal" {
- target_group_arn = aws_alb_target_group.internal.arn
- target_id = aws_instance.instance.id
- port = 3080
- }
- # Create a new alb listener
- resource "aws_alb_listener" "https_internal" {
- load_balancer_arn = aws_alb.internal.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_internal.arn
- default_action {
- target_group_arn = aws_alb_target_group.internal.arn
- type = "forward"
- }
- }
- resource "aws_alb_listener" "alb_3080_internal" {
- load_balancer_arn = aws_alb.internal.arn
- port = "3080"
- 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_internal.arn
- default_action {
- target_group_arn = aws_alb_target_group.internal.arn
- type = "forward"
- }
- }
- resource "aws_lb_listener" "http_internal" {
- load_balancer_arn = aws_alb.internal.arn
- port = "80"
- protocol = "HTTP"
- default_action {
- type = "redirect"
- redirect {
- port = "443"
- protocol = "HTTPS"
- status_code = "HTTP_301"
- }
- }
- }
- # #########################
- # # DNS Entry
- module "private_alb_dns_record" {
- source = "../../submodules/dns/private_CNAME_record"
- name = "${var.instance_name}-alb.${var.dns_info["private"]["zone"]}"
- target_dns_names = [aws_alb.internal.dns_name]
- dns_info = var.dns_info
- providers = {
- aws.c2 = aws.c2
- }
- }
- #----------------------------------------------------------------------------
- # ALB Security Group
- #----------------------------------------------------------------------------
- resource "aws_security_group" "alb_server_internal" {
- vpc_id = var.vpc_id
- # use name_prefix instead of name and create-before-destroy on security groups and alb target groups to make future changes easier,
- # otherwise, you get stuck in `destroying` during routine changes.
- name_prefix = "${var.instance_name}-alb-sg-internal"
- description = "Teleport LB SG"
- tags = merge(local.standard_tags, var.tags)
- lifecycle {
- create_before_destroy = true
- }
- }
- #----------------------------------------------------------------------------
- # INGRESS
- #----------------------------------------------------------------------------
- resource "aws_security_group_rule" "alb-internal-http-in" {
- type = "ingress"
- description = "HTTP - Inbound"
- from_port = "80"
- to_port = "80"
- protocol = "tcp"
- cidr_blocks = ["10.0.0.0/8"]
- security_group_id = aws_security_group.alb_server_internal.id
- }
- resource "aws_security_group_rule" "alb-internal-https-in" {
- type = "ingress"
- description = "HTTPS - Inbound"
- from_port = "443"
- to_port = "443"
- protocol = "tcp"
- cidr_blocks = ["10.0.0.0/8"]
- security_group_id = aws_security_group.alb_server_internal.id
- }
- resource "aws_security_group_rule" "alb-internal-3080-in" {
- type = "ingress"
- description = "3080 TCP - Inbound"
- from_port = "3080"
- to_port = "3080"
- protocol = "tcp"
- cidr_blocks = ["10.0.0.0/8"]
- security_group_id = aws_security_group.alb_server_internal.id
- }
- #----------------------------------------------------------------------------
- # EGRESS
- #----------------------------------------------------------------------------
- resource "aws_security_group_rule" "alb_internal-to_server" {
- type = "egress"
- description = "Allows the ALB to talk to the Sensu servers"
- from_port = 3080
- to_port = 3080
- protocol = "tcp"
- source_security_group_id = aws_security_group.instance.id
- security_group_id = aws_security_group.alb_server_internal.id
- }
|