【发布时间】:2017-09-25 04:53:40
【问题描述】:
Terraform 是否支持 Google 的内部负载均衡器? https://cloud.google.com/compute/docs/load-balancing/internal/
【问题讨论】:
标签: google-cloud-platform terraform
Terraform 是否支持 Google 的内部负载均衡器? https://cloud.google.com/compute/docs/load-balancing/internal/
【问题讨论】:
标签: google-cloud-platform terraform
截至 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"
}
}
【讨论】:
从技术上讲,它为您提供了运行它的相关功能:
https://www.terraform.io/docs/providers/google/r/compute_target_pool.html
不幸的是,它的文档很差,功能的布局意味着您必须设置许多相互依赖的健康检查、目标池、后端处理程序和转发规则来实现它,这与简单的其余的是。在terraform plan 和apply 上显示的错误消息也相当无用。
目前我正在尝试设置一个environment.tf,它可以复制我手动设置的现有负载平衡器,事实证明这是一个严重的试错挑战。 Hashicorp 需要在他们的文档中添加更多用例和解释。
【讨论】: