我目前正在尝试在Cloud Run上设置Google Cloud Endpoints,以便能够获得适用于我的Cloud Functions的OpenApi文档。我按照here中的说明进行了PoC,它运行良好。
现在我已经尝试使用terraform 0.12.24进行设置
服务端点
data "template_file" "openapi_spec" {
template = file("../../cloud_functions/openapi_spec.yaml")
vars = {
endpoint_service = local.service_name
feedback_post_target = google_cloudfunctions_function.feedbackPOST.https_trigger_url
}
}
resource "google_endpoints_service" "api-gateway" {
service_name = local.service_name
project = var.project_id
openapi_config = data.template_file.openapi_spec.rendered
depends_on = [
google_project_service.endpoints,
google_project_service.service-usage,
]
}
Cloud RUN
locals {
service_name = "${var.endpoint_service_name}.endpoints.${var.project_id}.cloud.goog"
}
resource "google_cloud_run_service" "api-management" {
name = "api-gateway-1233"
location = "europe-west1"
template {
spec {
containers {
image = "gcr.io/endpoints-release/endpoints-runtime-serverless:2"
env {
name = "ENDPOINTS_SERVICE_NAME"
value = local.service_name
}
}
}
}
traffic {
percent = 100
latest_revision = true
}
depends_on = [google_project_service.run]
}
如果现在尝试从Endpoints门户执行我的功能,则会出现以下错误
ENOTFOUND: Error resolving domain "https://function-api-gateway.endpoints.PROJECT_ID.cloud.goog"
这很有意义,因为我的端点服务应该使用由以下提供的云运行服务的主机网址:>
google_cloud_run_service.api-management.status[0].url
这意味着,我必须在上面的服务端点定义中使用它作为openApi定义中的服务名称和主机环境变量。只有设置了此选项,我才能再次使用env变量作为其URL本身来应用我的云运行服务。
这是一个循环依赖性,我不知道如何解决
。非常感谢您的帮助!我目前正在尝试在Cloud Run上设置Google Cloud Endpoints,以便能够获得适用于我的Cloud Functions的OpenApi文档。我按照此处的PoC指示进行了操作,效果很好。...
根据我的理解看了您的配置和Cloud Run with Cloud Endpoints的文档后,就没有循环依赖,而是对必须满足的创建资源的排序。