Using the load balancer module with something other than ECS?

This message is extracted from a ticket originally emailed to support@gruntwork.io. Names and URLs have been removed where appropriate.

We are planning to migrate our infrastructure from Ansible and everything-running-on-hosts to Docker containers, eventually to use something like ECS, using Terragrunt.

As the first step, we would like to deploy an ALB that fronts a customizable aws_lb_target_group. We plan to move our existing servers into this new aws_lb_target_group and obsolete usage of HAProxy.

I was trying to use https://github.com/gruntwork-io/module-load-balancer but it looks like there is an assumption about usage of ECS for running applications. How do I go about creating a new target group for my ALB (in addition to the default blackhole target group)? Is there an example for creating an ALB for a custom aws_lb_target_group that you can point me to?

The alb module in module-load-balancer should work with any service and not just ECS services. You can deploy the ALB as shown here and then add target groups and listener rules using the aws_lb_target_group and aws_lb_listener_rule resources, respectively.

Rough example:

module "alb" {
  source = "git::git@github.com:gruntwork-io/module-load-balancer.git//modules/alb?ref=v0.7.0"

  alb_name         = "my-alb"
  environment_name = "stage"
  is_internal_alb  = false

  http_listener_ports = [80]

  vpc_id         = "${var.vpc_id}"
  vpc_subnet_ids = "${var.vpc_subnet_ids}"
}

resource "aws_lb_target_group" "example" {
  name     = "example"
  port     = 80
  protocol = "HTTP"
  vpc_id   = "${var.vpc_id}"
}

resource "aws_lb_listener_rule" "example" {
  listener_arn = "${lookup(module.alb.alb.listener_arns, 80)}"
  priority     = 100

  action {
    type             = "forward"
    target_group_arn = "${aws_lb_target_group.example.arn}"
  }

  condition {
    field  = "path-pattern"
    values = ["/foo/*"]
  }
}