Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconcouchbase-cluster
file-type-iconcouchbase-commons
file-type-iconcouchbase-iam-policies
file-type-iconcouchbase-server-security-group-rules
file-type-iconinstall-couchbase-server
file-type-iconinstall-sync-gateway
file-type-iconload-balancer-target-group
file-type-iconload-balancer
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconrun-couchbase-server
file-type-iconrun-replication
file-type-iconrun-sync-gateway
file-type-iconsync-gateway-security-group-rules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-icon.pre-commit-hooks.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconcouchbase-cluster
file-type-iconcouchbase-commons
file-type-iconcouchbase-iam-policies
file-type-iconcouchbase-server-security-group-rules
file-type-iconinstall-couchbase-server
file-type-iconinstall-sync-gateway
file-type-iconload-balancer-target-group
file-type-iconload-balancer
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconrun-couchbase-server
file-type-iconrun-replication
file-type-iconrun-sync-gateway
file-type-iconsync-gateway-security-group-rules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-icon.pre-commit-hooks.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
Couchbase

Couchbase

Deploy a Couchbase cluster. Supports automatic bootstrapping, Sync Gateway, Web Console UI, cross-region replication, and auto healing.

Code Preview

Preview the Code

mobile file icon

README.md

down

Load Balancer

This folder contains a Terraform module that can be used to deploy an Application Load Balancer (ALB) in front of your Couchbase and/or Sync Gateway cluster to:

  1. Perform health checks on the servers in the cluster and automatically replace them when they fail.
  2. Distribute traffic across Couchbase Server nodes. Note that you should ONLY use the load balancer for the Couchbase Web Console and NOT any of the API paths (see the Couchbase FAQ for more info).
  3. Distribute traffic across multiple Sync Gateway nodes.

Note that this module solely deploys the Load Balancer, as you may want to share one load balancer across multiple applications. To deploy Target Groups, health checks, and routing rules, use the load-balancer-target-group module.

See the examples folder for fully working sample code.

How do you use this module?

This folder defines a Terraform module, which you can use in your code by adding a module configuration and setting its source parameter to URL of this folder:

module "load_balancer" {
  # TODO: replace <VERSION> with the latest version from the releases page: https://github.com/gruntwork-io/terraform-aws-couchbase/releases
  source = "github.com/gruntwork/terraform-aws-couchbase//modules/load-balancer?ref=<VERSION>"
  
  name       = "couchbase-load-balancer"
  vpc_id     = "vpc-abcd1234"
  subnet_ids = ["subnet-abcd1234", "subnet-efgh5678"]

  http_listener_ports = [80]

  https_listener_ports_and_certs = [
    {
      port = 443
      certificate_arn = "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"
    }
  ]
  
  inbound_from_cidr_blocks = ["0.0.0.0/0"]

  # ... See variables.tf for the other parameters you must define for this module
}

The above code will create a Load Balancer.

Note the following:

  • source: Use this parameter in the module to specify the URL of the load-balancer module. The double slash (//) is intentional and required. Terraform uses it to specify subfolders within a Git repo (see module sources). The ref parameter specifies a specific Git tag in this repo. That way, instead of using the latest version of this module from the master branch, which will change every time you run Terraform, you're using a fixed version of the repo.

  • http_listener_ports: Which ports the load balancer should listen on for HTTP requests.

  • https_listener_ports_and_certs: Whic ports the load balancer should listen on for HTTPS requests and which TLS certs to use with those ports.

  • allow_inbound_from_cidr_blocks: Use this variable to specify which IP address ranges can connect to the Load Balancer. You can also use allow_inbound_from_security_groups to allow specific security groups to connect.

How is the ALB configured?

The ALB in this module is configured as follows:

  1. Listeners: The Load Balancer will create a listener for each port specified in http_listener_ports and https_listener_ports_and_certs.

  2. TLS certificates: Each port you specify via the https_listener_ports_and_certs should also include a certificate_arn parameter to specify the ARN of a TLS certificate. This must be the ARN of a certificate in ACM or IAM.

  3. DNS: You can use the route53_records variable to create one more more DNS A Records in Route 53 that point to the Load Balancer. This allows you to use custom domain names to access the Load Balancer. Note that the TLS certificate you use with the HTTPS listener must be issued for the same domain name(s)!

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?