Terraform - GCP - 将 IP 地址链接到链接到云存储桶的负载均衡器

标签 terraform terraform-provider-gcp

我想要的是:

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

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

我目前拥有的:

  • 一个已经手动创建的存储桶,名为“静态图像”
  • 链接到所述存储桶的负载均衡器,创建于
    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 等效于“前端配置”
  • 最佳答案

    看起来您只是缺少一个 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}"
    }
    

    希望这可以帮助!

    关于Terraform - GCP - 将 IP 地址链接到链接到云存储桶的负载均衡器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56009157/

    相关文章:

    terraform - 拆分 terraform tfstate 文件

    google-cloud-platform - Terraform Bigquery 创建表替换表而不是编辑

    google-cloud-platform - 想要通过 terraform 将多个 Google Cloud IAM 角色分配给服务帐户

    amazon-web-services - terraform 中的无效计数参数

    kubernetes - 如何水平自动缩放 Kubernetes 部署

    terraform - 在创建资源之前,我们可以在 Terraform 中匹配多个条件吗?

    google-cloud-platform - 同时创建多个具有私有(private) IP 的 Google Cloud SQL 实例时如何修复 "An Unknown Error Occurred"?

    terraform-provider-gcp - 如何安全地从 google_project_iam_policy 资源迁移到 google_project_iam_member?

    google-cloud-platform - 将 Terraform 输出转储到本地文件

    要通过删除空对象进行映射的 Terraform 元组?