martinrusev
9/13/2017 - 1:48 PM

alb_example.tf

alb_example.tf

resource "aws_alb" "alb_grafana" {
  name            = "alb-energy-grafana"
  internal        = true
  security_groups = ["${aws_security_group.sec_energy_grafana_elb.id}"]
  subnets         = ["${var.SUBNETS}"]


  tags {
    Name  = "alb-energy-grafana"
    Owner = "${var.OWNER}"
    Creator = "${var.OWNER}"
    Product = "Energy"
    CostCenter  = "Energy"
  }
}


resource "aws_alb_listener" "alb_grafana_listener" {
  load_balancer_arn = "${aws_alb.alb_grafana.arn}"
  port              = "443"
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-2016-08"
  certificate_arn   = "${data.aws_acm_certificate.grafana_ssl_cert.arn}"

  default_action {
    target_group_arn = "${aws_alb_target_group.alb_grafana_target_group.arn}"
    type             = "forward"
  }
}

resource "aws_alb_target_group" "alb_grafana_target_group" {
  name     = "alb-energy-grafana-tg"
  port     = 3000
  protocol = "HTTP"
  vpc_id   = "${var.VPC_ID}"

  health_check {
    healthy_threshold   = 2
    interval            = 15
    path                = "/"
    timeout             = 10
    unhealthy_threshold = 2
    matcher             = 302
  }
}


resource "aws_alb_target_group_attachment" "alb_grafana_tg_instance" {
  target_group_arn = "${aws_alb_target_group.alb_grafana_target_group.arn}"
  target_id        = "${aws_instance.grafana_server.id}"
  port             = 3000
}