Terraform:云 运行 服务上的云端点?
Terraform: Cloud Endpoints on a Cloud Run service?
有没有办法在云 运行 服务上 运行 云端点?
假设我有以下 main.tf
,并且我想在定义我的 Cloud Endpoints 服务时使用 Cloud 运行 的 URL。
URL 应该存储在 google_cloud_run_service.cloud-run.status.url
下。
下面的配置会引发错误。
来自terraform plan
的输出:
Error: Unsupported attribute
on main.tf line 411, in resource "google_endpoints_service" "cloud-run":
411: service_name = "${google_cloud_run_service.cloud-run.status.url}"
This value does not have any attributes.
main.tf:
[...]
#############
# Cloud Run #
#############
resource "google_cloud_run_service" "cloud-run" {
name = "cloud-run"
provider = "google-beta"
location = "europe-west1"
metadata {
namespace = "${var.gcp_project[var.env]}"
}
spec {
containers {
image = "gcr.io/endpoints-release/endpoints-runtime-serverless@sha256:a12b14dd6d31a88637ca7c9e63724ad542226d9509421ba08ed4452a91ce751e"
}
container_concurrency = var.env != "dev" ? 0 : 1
}
}
###################
# Cloud Endpoints #
###################
resource "google_endpoints_service" "pre-pairing-api" {
# The service name, AFAIK, should be Cloud Run's URL:
service_name = "${google_cloud_run_service.cloud-run.status.url}" # <--------
openapi_config = <<EOF
swagger: '2.0'
info:
title: Pre-pairing
description: API on Cloud Endpoints with a Google Cloud Functions backend...
version: 1.0.0
# Same applies to the host. It should be, AFAIK, Cloud Run's URL.
host: "${google_cloud_run_service.cloud-run.status.url}" # <--------
[...]
我是否遗漏或误解了什么?
提前致谢!
您可以按照此 documentation.
为 Cloud 运行 设置 Cloud Endpoints
您的 main.tf 文件不会等待云 运行 服务准备就绪,以便继续将可扩展服务代理 (ESP) 容器部署到云的后续步骤 运行.
示例用法 here 展示了如何使用局部变量等待云 运行 服务就绪。
我找到了解决方案:
# main.tf
[...]
#############
# Cloud Run #
#############
resource "google_cloud_run_service" "cloud-run" {
[...]
}
# The URL was located under `status[0].url` instead of `status.url`.
# I have created a local variable to store its value.
locals {
cloud_run_url = google_cloud_run_service.cloud-run.status[0].url
}
###################
# Cloud Endpoints #
###################
resource "google_endpoints_service" "some-api" {
service_name = "${replace(local.cloud_run_url, "https://", "")}" # <--------
openapi_config = <<EOF
swagger: '2.0'
info:
title: Some-API
description: API on Cloud Endpoints with a Google Cloud Functions backend...
version: 1.0.0
host: "${replace(local.cloud_run_url, "https://", "")}" # <--------
[...]
EOF
depends_on = ["google_cloud_run_service.cloud-run"]
我还不能 100% 确定这是否适用于第一个 运行。尽管如此,我希望 depends_on
(见上文)处理这种依赖关系并等待创建 Cloud 运行,然后再继续创建 Cloud Endpoints 服务。
有没有办法在云 运行 服务上 运行 云端点?
假设我有以下 main.tf
,并且我想在定义我的 Cloud Endpoints 服务时使用 Cloud 运行 的 URL。
URL 应该存储在 google_cloud_run_service.cloud-run.status.url
下。
下面的配置会引发错误。
来自terraform plan
的输出:
Error: Unsupported attribute
on main.tf line 411, in resource "google_endpoints_service" "cloud-run":
411: service_name = "${google_cloud_run_service.cloud-run.status.url}"
This value does not have any attributes.
main.tf:
[...]
#############
# Cloud Run #
#############
resource "google_cloud_run_service" "cloud-run" {
name = "cloud-run"
provider = "google-beta"
location = "europe-west1"
metadata {
namespace = "${var.gcp_project[var.env]}"
}
spec {
containers {
image = "gcr.io/endpoints-release/endpoints-runtime-serverless@sha256:a12b14dd6d31a88637ca7c9e63724ad542226d9509421ba08ed4452a91ce751e"
}
container_concurrency = var.env != "dev" ? 0 : 1
}
}
###################
# Cloud Endpoints #
###################
resource "google_endpoints_service" "pre-pairing-api" {
# The service name, AFAIK, should be Cloud Run's URL:
service_name = "${google_cloud_run_service.cloud-run.status.url}" # <--------
openapi_config = <<EOF
swagger: '2.0'
info:
title: Pre-pairing
description: API on Cloud Endpoints with a Google Cloud Functions backend...
version: 1.0.0
# Same applies to the host. It should be, AFAIK, Cloud Run's URL.
host: "${google_cloud_run_service.cloud-run.status.url}" # <--------
[...]
我是否遗漏或误解了什么? 提前致谢!
您可以按照此 documentation.
为 Cloud 运行 设置 Cloud Endpoints您的 main.tf 文件不会等待云 运行 服务准备就绪,以便继续将可扩展服务代理 (ESP) 容器部署到云的后续步骤 运行.
示例用法 here 展示了如何使用局部变量等待云 运行 服务就绪。
我找到了解决方案:
# main.tf
[...]
#############
# Cloud Run #
#############
resource "google_cloud_run_service" "cloud-run" {
[...]
}
# The URL was located under `status[0].url` instead of `status.url`.
# I have created a local variable to store its value.
locals {
cloud_run_url = google_cloud_run_service.cloud-run.status[0].url
}
###################
# Cloud Endpoints #
###################
resource "google_endpoints_service" "some-api" {
service_name = "${replace(local.cloud_run_url, "https://", "")}" # <--------
openapi_config = <<EOF
swagger: '2.0'
info:
title: Some-API
description: API on Cloud Endpoints with a Google Cloud Functions backend...
version: 1.0.0
host: "${replace(local.cloud_run_url, "https://", "")}" # <--------
[...]
EOF
depends_on = ["google_cloud_run_service.cloud-run"]
我还不能 100% 确定这是否适用于第一个 运行。尽管如此,我希望 depends_on
(见上文)处理这种依赖关系并等待创建 Cloud 运行,然后再继续创建 Cloud Endpoints 服务。