有办法在云运行服务上运行云终结点吗?
假设我有下面的main.tf,在定义Cloud服务时,我希望使用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}" # <--------
[...]我是错过了什么还是误解了什么?提前感谢!
发布于 2019-10-29 12:27:04
我找到了一个解决办法:
# 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。
https://stackoverflow.com/questions/58596309
复制相似问题