【问题标题】:Terraform - GCP - link an ip address to a load balancer linked to a cloud storage bucketTerraform - GCP - 将 IP 地址链接到链接到云存储桶的负载均衡器
【发布时间】:2019-09-24 07:45:09
【问题描述】:

我想要什么:

我希望有一个static.example.com DNS 记录链接到 GCS 中包含我的静态图像的存储桶。

当我通过 Cloudflare 管理我的 DNS 时,我认为我需要利用 GCP 可以为我分配一个 anycast-IP 的事实,将该 IP 链接到 GCP 负载均衡器,该负载均衡器将链接到存储桶

我目前拥有的:

  • 已手动创建的存储桶,名为“static-images”

  • 链接到所述存储桶的负载均衡器,使用

    创建
    resource "google_compute_backend_bucket" "image_backend" {
      name        = "example-static-images"
      bucket_name = "static-images"
      enable_cdn  = true
    }
    
  • 链接到我的存储桶的路由

    resource "google_compute_url_map" "urlmap" {
      name            = "urlmap"
      default_service = "${google_compute_backend_bucket.image_backend.self_link}"
    
      host_rule {
        hosts        = ["static.example.com"]
        path_matcher = "allpaths"
      }
    
      path_matcher {
        name            = "allpaths"
        default_service = "${google_compute_backend_bucket.image_backend.self_link}"
    
        path_rule {
          paths   = ["/static"]
          service = "${google_compute_backend_bucket.image_backend.self_link}"
        }
      }
    }
    
  • 一个ip创建的:

    resource "google_compute_global_address" "my_ip" {
      name = "ip-for-static-example-com"
    }
    

我错过了什么:

  • 从 Web 控制台创建负载平衡器时,terraform 相当于“前端配置”

【问题讨论】:

    标签: terraform terraform-provider-gcp


    【解决方案1】:

    看起来您只是缺少forwarding ruletarget proxy

    google_compute_global_forwarding_rule 上的 terraform 文档有一个很好的例子。

    例如:

    resource "google_compute_global_forwarding_rule" "default" {
      name = "default-rule"
      target = "${google_compute_target_http_proxy.default.self_link}"
      port_range = 80     // or other e.g. for ssl
    
      ip_address = "${google_compute_global_address.my_ip.address}"
    }
    
    resource "google_compute_target_http_proxy" "default" {  // or https proxy
      name        = "default-proxy"
      description = "an HTTP proxy"
      url_map     = "${google_compute_url_map.urlmap.self_link}"
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2020-03-14
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多