我使用在 GCP 控制台上创建了一个全局(多区域)TCP(代理)LB
- 单前端配置
- 后端类型的四种后端配置: 4 个不同区域的实例组。
- 以及一个完整的后端配置的健康检查
现在同样无法使用 Terraform 创建下面是我的完整代码:
问题:负载均衡器未使用名称创建:在google_compute_target_tcp_proxy中使用名称创建:仅在google_compute_backend_service如果只传递一个后端,如果我传递多个通过计数传递的后端,则创建多个负载均衡器,而不是将所有后端附加到一个负载均衡器。谁能建议如何将多个后端附加到单个google_compute_target_tcp_proxy?我是 terraform 新手,我在 Terraform 文档中没有找到任何详细信息。
provider "google" {
credentials = file(var.credentials_file)
project = var.project_id
}
provider "google-beta" {
credentials = file(var.credentials_file)
project = var.project_id
}
resource "google_compute_global_forwarding_rule" "default" {
#count = length(var.zones)
name = "frontend-service-mig-test" #We can have single FE IP
#target = google_compute_target_tcp_proxy.default[count.index].id
target = google_compute_target_tcp_proxy.default.id
port_range = "443"
load_balancing_scheme = "EXTERNAL"
}
resource "google_compute_target_tcp_proxy" "default" {
#count = length(var.zones)
name = "test-proxy" # This name wont be visible on gui.
#backend_service = google_compute_backend_service.default[count.index].id
backend_service = google_compute_backend_service.default.id
}
resource "google_compute_backend_service" "default" {
count = length(var.zones)
name = "mig-test-${count.index}-backend-service"
load_balancing_scheme = "EXTERNAL"
protocol = "TCP"
timeout_sec = 10
port_name = "https"
health_checks = [google_compute_health_check.default.id]
backend {
#group = "https://www.googleapis.com/compute/v1/projects/terraform-playground-301207/zones/northamerica-northeast1-a/instanceGroups/mig-test-0"
group = "https://www.googleapis.com/compute/v1/projects/terraform-playground-301207/zones/${var.zones[count.index]}/instanceGroups/mig-test-${count.index}"
balancing_mode = "UTILIZATION"
capacity_scaler = 1
max_utilization = 0.8
}
}
resource "google_compute_health_check" "default" {
count = length(var.zones)
provider = google-beta
name = "health-check-mig-test-${count.index}"
timeout_sec = 5
check_interval_sec = 5
healthy_threshold = 2
unhealthy_threshold = 2
log_config {
enable = false
}
tcp_health_check {
port = "443"
}
}