Reputation: 119
Does Terraform support Google's Internal Load Balancer? https://cloud.google.com/compute/docs/load-balancing/internal/
Upvotes: 4
Views: 3798
Reputation: 3509
As of September 2017, it certainly does! Unfortunately, the documentation for it is not that great.
Here's a very rough example, might not just work via copy/paste!
resource "google_compute_instance_group" "elasticsearch-cluster" {
name = "elasticsearch-cluster"
description = "Terraform test instance group"
instances = [
"${google_compute_instance.elasticsearch-compute-instance.*.self_link}"
]
named_port {
name = "elasticsearch-api"
port = "9200"
}
named_port {
name = "elasticsearch-transport"
port = "9300"
}
zone = "us-central1-a"
}
resource "google_compute_forwarding_rule" "elasticsearch-forwarding-rule" {
name = "elasticsearch-lb"
load_balancing_scheme = "INTERNAL"
backend_service = "${google_compute_region_backend_service.elasticsearch-lb.self_link}"
ports = [ "9200", "9300" ]
}
resource "google_compute_region_backend_service" "elasticsearch-lb" {
name = "elasticsearch-lb"
protocol = "TCP"
timeout_sec = 10
session_affinity = "NONE"
backend {
group = "${google_compute_instance_group.elasticsearch-cluster.self_link}"
}
health_checks = ["${google_compute_health_check.elasticsearch-healthcheck.self_link}"]
}
resource "google_compute_health_check" "elasticsearch-healthcheck" {
name = "elasticsearch-healthcheck"
check_interval_sec = 5
timeout_sec = 5
tcp_health_check {
port = "9200"
}
}
Upvotes: 5
Reputation: 63
It technically does, in the sense that it provides you with the relevant functions to run it:
https://www.terraform.io/docs/providers/google/r/compute_target_pool.html
Unfortunately, the documentation on it is quite poor and the layout of the functions mean that you have to set up a number of interdependent health checks, target pools, backend handlers and forwarding rules to achieve it, very different to how straightforward the rest of it is. The error messages displayed on terraform plan
and apply
are also rather unhelpful.
Currently I'm trying to setup a environment.tf
that replicates an existing load balancer I manually setup and it's proving to be serious trial and error challenge. Hashicorp need to add a lot more use cases and explanations to their docs.
Upvotes: 0