terraform load balancer https code example

Example: terraform aws load balancer

data "aws_subnet_ids" "network_lb" {
  vpc_id = var.vpc_id

  tags = {
    type = "Public"
  }
}
resource "aws_lb" "network_lb" {
  name               = "test-load-balancer"
  load_balancer_type = "network"
  subnets            = data.aws_subnet_ids.network_lb.ids

  enable_cross_zone_load_balancing = true
}
resource "aws_lb_target_group" "network_lb" {
  port        = 8080
  protocol    = "TCP"
  vpc_id      = var.vpc_id

  depends_on = [
    aws_lb.network_lb
  ]

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_attachment" "target" {
  autoscaling_group_name = lb_autoscaling
  alb_target_group_arn   = aws_lb_target_group.network_lb.arn
}

resource "aws_security_group" "lb_sg" {
  description = "Allow connection between LoadBalancer and target"
  vpc_id      = var.vpc_id
}

resource "aws_security_group_rule" "ingress" {
  security_group_id = aws_security_group.this.id
  from_port         = 
  to_port           = 
  protocol          = "tcp"
  type              = "ingress"
  cidr_blocks       = ["0.0.0.0/0"]
}

Tags:

Misc Example