Browse the Repo

file-type-icon.circleci
file-type-icon.github
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconauto-discovery
file-type-iconbeats-iam-policies
file-type-iconelastalert-iam-policies
file-type-iconelastalert-security-group-rules
file-type-iconelastalert
file-type-iconelasticsearch-cluster-backup
file-type-iconelasticsearch-cluster-restore
file-type-iconelasticsearch-cluster
file-type-iconelasticsearch-iam-policies
file-type-iconelasticsearch-security-group-rules
file-type-iconinstall-collectd
file-type-iconinstall-elastalert
file-type-iconinstall-elasticsearch
file-type-iconinstall-filebeat
file-type-iconinstall-kibana
file-type-iconinstall-logstash
file-type-iconkibana-cluster
file-type-iconkibana-security-group-rules
file-type-iconload-balancer-alb-target-group
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconlogstash-cluster
file-type-iconlogstash-iam-policies
file-type-iconlogstash-security-group-rules
file-type-iconrun-collectd
file-type-iconrun-elastalert
file-type-iconrun-elasticsearch
file-type-iconrun-filebeat
file-type-iconrun-kibana
file-type-iconrun-logstash
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.md
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...

Browse the Repo

file-type-icon.circleci
file-type-icon.github
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconauto-discovery
file-type-iconbeats-iam-policies
file-type-iconelastalert-iam-policies
file-type-iconelastalert-security-group-rules
file-type-iconelastalert
file-type-iconelasticsearch-cluster-backup
file-type-iconelasticsearch-cluster-restore
file-type-iconelasticsearch-cluster
file-type-iconelasticsearch-iam-policies
file-type-iconelasticsearch-security-group-rules
file-type-iconinstall-collectd
file-type-iconinstall-elastalert
file-type-iconinstall-elasticsearch
file-type-iconinstall-filebeat
file-type-iconinstall-kibana
file-type-iconinstall-logstash
file-type-iconkibana-cluster
file-type-iconkibana-security-group-rules
file-type-iconload-balancer-alb-target-group
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconlogstash-cluster
file-type-iconlogstash-iam-policies
file-type-iconlogstash-security-group-rules
file-type-iconrun-collectd
file-type-iconrun-elastalert
file-type-iconrun-elasticsearch
file-type-iconrun-filebeat
file-type-iconrun-kibana
file-type-iconrun-logstash
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.md
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...
Elasticsearch (self-hosted)

Elasticsearch (self-hosted)

Deploy a self-hosted Elasticsearch cluster. Supports automatic bootstrap, zero-downtime rolling deployment, auto healing, backup, and recovery.

Code Preview

Preview the Code

mobile file icon

README.md

down

Load Balancer Target Group Module

This module can be used to create a Target Group and Listener Rules for an Application Load Balancer created with the alb module.

The reason the load-balancer-alb-target-group module is separate is that you may wish to create multiple target groups for a single load balancer.

See the examples folder for fully working sample code.

How do you use this module?

Imagine you've deployed ELK using the elasticsearch-cluster and a Load Balancer using the load-balancer module:

module "elasticsearch" {
  # TODO: replace <VERSION> with the latest version from the releases page: https://github.com/gruntwork-io/terraform-aws-elk/releases
  source = "github.com/gruntwork/terraform-aws-elk//modules/elasticsaearch-cluster?ref=<VERSION>"
  
  cluster_name = var.cluster_name
  
  health_check_type = "ELB"
  
  # ... (other params omitted) ...
}

module "alb" {
  # TODO: replace <VERSION> with the latest version from the releases page: https://github.com/gruntwork-io/terraform-aws-load-balancer/releases
  source = "github.com/gruntwork/terraform-aws-load-balancer//modules/alb?ref=<VERSION>"
  
  alb_name         = var.alb_name

  http_listener_ports = [9200]

  # ... (other params omitted) ...
}

Note the following:

  • http_listener_ports: This tells the Load Balancer to listen for HTTP requests on port 9200.

To create Target Groups and Listener Rules for Elasticsearch, you need to use the load-balancer-alb-target-group module as follows:

module "elasticsearch_target_group" {
  # TODO: replace <VERSION> with the latest version from the releases page: https://github.com/gruntwork-io/terraform-aws-elk/releases
  source = "github.com/gruntwork/terraform-aws-elk//modules/load-balancer-alb-target-group?ref=<VERSION>"

  target_group_name = "${var.elasticsearch_cluster_name}-es-tg"
  port              = var.elasticsearch_api_port
  health_check_path = "/"

  http_listener_arns      = [lookup(module.alb.http_listener_arns, var.elasticsearch_api_port, "")]
  num_http_listener_arns  = 1
  
  listener_rule_starting_priority = 100

  # If you are deploying a module based on a Server Group vs an ASG
  using_server_group      = true
  
  # HTTP or HTTPS depending on whether you are using SSL or not.
  protocol = var.alb_target_group_protocol
    
  # ... See vars.tf for the other parameters you must define for this module
}

Note the following:

  • asg_name: Use this param to attach the Target Group to an Auto Scaling Group (ASG) used under the hood in the Kibana cluster so that each EC2 Instance automatically registers with the Target Group, goes through health checks, and gets replaced if it is failing health checks. asg_name param is only used if using_server_group is false.

  • listener_arns: Specify the ARN of the HTTP listener from the ALB. The Elasticsearch Target Group uses Elasticsearch's port (default 9200).

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?