【问题标题】:terraform GCP http(s) Loadbalancerterraform GCP https) 负载均衡器
【发布时间】: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


【解决方案1】:

您还可以通过以下方式即时分配外部 IP:

resource "google_compute_global_address" "L7LB_IP_ADDRESS" {
  name                  = "l7lb-external-ip-address"
}

然后在转发规则(前端)中,设置ip地址:

resource "google_compute_global_forwarding_rule" "EXTERNAL_FWD_RULE_HTTP" {
  name                  = "frontend-80"
  ip_address            = google_compute_global_address.L7LB_IP_ADDRESS.address
  port_range            = "80"
}
resource "google_compute_global_forwarding_rule" "EXTERNAL_FWD_RULE_HTTPS" {
  name                  = "frontend-443"
  ip_address            = google_compute_global_address.L7LB_IP_ADDRESS.address
  port_range            = "443"
}

【讨论】:

    【解决方案2】:

    提供的 IP 地址资源需要在 Terraform 中具有 SHARED_LOADBALANCER_VIP 用途

    SHARED_LOADBALANCER_VIP 用于多个内部负载平衡器可以使用的地址。 https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_address

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-18
      • 2021-08-31
      • 2014-02-12
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      相关资源
      最近更新 更多