【发布时间】:2020-05-08 22:41:58
【问题描述】:
我正在尝试在 GCP 上使用 terraform 创建 HTTP(S) 负载均衡器。我希望它同时为 HTTP 和 HTTPS 客户端提供服务。我正在使用以下方法来创建 LB 的前端部分(google_compute_global_forwarding_rule)。
// SSL
resource "google_compute_global_forwarding_rule" "default-ssl" {
name = "frontend-https"
target = google_compute_target_https_proxy.default-ssl.self_link
port_range = "443"
}
resource "google_compute_target_https_proxy" "default-ssl" {
provider = google-beta
name = "target-proxy-ssl"
description = "a description"
ssl_certificates = ["mysslcert"]
url_map = google_compute_url_map.default.self_link
}
// non SSL
resource "google_compute_global_forwarding_rule" "default" {
name = "frontend-http"
target = google_compute_target_http_proxy.default.self_link
port_range = "80"
}
resource "google_compute_target_http_proxy" "default" {
project = var.project_id
provider = google-beta
name = "target-proxy"
description = "a description"
url_map = google_compute_url_map.default.self_link
}
问题在于,它分配了两个 IP 地址;一种用于 HTTP,一种用于 HTTPS。 但是当我在 GCP 上手动创建负载均衡器时(没有 terraform),我可以创建一个 IP 地址并选择协议。通过这样做,我可以在创建下一个前端规则时使用相同的 IP 地址。
已创建地形;
手动创建;
感谢您对创建只有一个 IP 地址的负载平衡器的帮助。
【问题讨论】:
-
您需要先分配IP地址,然后在创建负载均衡前端时选择地址。
-
所以我按照@john Hanley 的建议创建了一个 IP 并将其传递给模块,如下所示; resource "google_compute_global_forwarding_rule" "default-ssl" { name = "前端-https" ip_address = var.ext_static_ip target = google_compute_target_https_proxy.default-ssl.self_link port_range = "443" }
标签: google-cloud-platform terraform-provider-gcp