Terraform - Google内部负载均衡器

时间:2016-10-13 20:24:02

标签: google-cloud-platform terraform

Terraform是否支持Google的内部负载均衡器? https://cloud.google.com/compute/docs/load-balancing/internal/

2 个答案:

答案 0 :(得分:5)

截至2017年9月,它确实如此!不幸的是,它的文档并不是很好。

这是一个非常粗略的例子,可能不仅仅是通过复制/粘贴工作!

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"
  }
}

答案 1 :(得分:0)

从某种意义上说,它提供了运行它的相关功能:

https://www.terraform.io/docs/providers/google/r/compute_target_pool.html

不幸的是,它上面的文档很差,而且函数的布局意味着你必须设置一些相互依赖的健康检查,目标池,后端处理程序和转发规则才能实现它,这与简单的方法截然不同剩下的就是。 <{1}}和terraform plan上显示的错误消息也无济于事。

目前,我正在尝试设置apply复制现有负载均衡器,我手动设置,这证明是严重的试验和错误挑战。 Hashicorp需要在他们的文档中添加更多用例和解释。