GCP url 映射为不同后端服务创建路径规则

GCP url map creating path rules for different backend services

下面是我的地形脚本。我已经设置了必要的转发规则和目标 http 代理。后端服务也存在。我可以访问/images/*下的所有路径,但是我无法访问/videos/*下的路径。从脚本中,默认后端服务是 backend-lb-prod,这是路径 /images/* 所在的后端服务。我将默认后端服务切换为 backend-lb,我现在可以访问 /videos/* 但不能访问 /images/*

resource "google_compute_url_map" "url-map-be" {
  name            = "${var.platform_name}-url-map-be-prod"
  default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"

  host_rule {
    hosts        = ["${var.backend_address_name}"]
    path_matcher = "allpaths"
  }

  path_matcher {
    name            = "allpaths"
    default_service = "${google_compute_backend_service.backend-lb-prod.self_link}"

    path_rule {
      paths   = [“/images"]
      service = "${google_compute_backend_service.backend-lb-prod.self_link}"
    }  

    path_rule {
      paths   = [“/images/*"]
      service = "${google_compute_backend_service.backend-lb-prod.self_link}"
    } 

    path_rule {
      paths   = ["/videos"]
      service = "${google_compute_backend_service.backend-lb.self_link}"
    }  

    path_rule {
      paths   = ["/videos/*"]
      service = "${google_compute_backend_service.backend-lb.self_link}"
    }

  }
}

当我在 google 控制台上 运行 测试 url 地图时,这是我得到的错误

Invalid value for field 'resource': ''. Test failure: Expect URL ‘*.*.*.*/videos/go' 
to map to service ‘***93-BACKEND_SERVICE-**-backend-lb', but actually mapped to 
'***93-BACKEND_SERVICE-**-backend-lb-prod’.

这就是地形 documentationgoogle_compute_url_map 的说明方式。在这种情况下我错过了什么。

更新

我添加了 /videos/images 路径,上面的错误消失了。但是从应用的日志来看,流量还是通过默认的后台服务发送的。

希望这对其他人有帮助。在 host_rule 下,hosts 最初是一个 IP 地址。我也将它更改为域名,但它仍然将所有流量发送到默认后端服务。我将其更改为 *,它现在可以按预期工作。另外需要注意的是,非默认后端服务的路径需要几分钟才能访问。

host_rule {
  hosts        = ["*"]
  path_matcher = "allpaths"
}