gpt4 book ai didi

google-cloud-platform - 想要通过 Terraform 部署 Google Cloud Run 服务

转载 作者:行者123 更新时间:2023-12-01 21:45:49 25 4
gpt4 key购买 nike

我想使用 Terraform 部署谷歌云运行服务。当我尝试通过“端口” block 部署以定义容器端口时出现错误,我必须从模板标签传递容器端口但无法做到这一点。这是我的 .tf 文件 -

resource "google_cloud_run_service" "default" {
name = "cloudrun-srv"
location = "us-central1"

template {
spec {
containers {
image = "us.gcr.io/xxxxxx/xxxx.app"

port {
container_port = 19006
}
}
}
}

traffic {
percent = 100
latest_revision = true
}
}

data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = [
"allUsers",
]
}
}

resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.default.location
project = google_cloud_run_service.default.project
service = google_cloud_run_service.default.name

policy_data = data.google_iam_policy.noauth.policy_data
}

output "url" {
value = "${google_cloud_run_service.default.status[0].url}"
}

使用端口标记,这里是错误 - enter image description here

如果我没有通过端口 block ,这里是错误 - enter image description here

我必须将容器端口值传递为 19006,因为我的容器仅在该端口上运行。我如何传递容器端口 19006 而不是默认端口 8080。 enter image description here

最佳答案

我查看了 Google 公开的用于创建 Cloud Run 服务的 REST API。

这从这里的条目开始:

POST https://{endpoint}/apis/serving.knative.dev/v1/{parent}/services

正文中包含 Service .

其中包含 ServiceSpec

其中包含 RevisionRemplate

其中包含 RevisionSpec

其中包含 Container

其中包含 ContainerPort

如果我们现在将其映射到 Terraform 扩展的源以处理 Cloud Run 服务的创建,我们会发现:

https://github.com/terraform-providers/terraform-provider-google/blob/2dc3da62e3844d14fb2136e09f13ea934b038411/google/resource_cloud_run_service.go#L90

在评论中,我们发现以下内容:

In the context of a Revision, we disallow a number of the fields of this Container, including: name, ports, and volumeMounts. The runtime contract is documented here: https://github.com/knative/serving/blob/master/docs/runtime-contract.md

虽然此时 name 和 volumeMounts 对我来说似乎ok,但我没有感觉到 ports 未映射的原因。

虽然如此,我似乎看到无法通过 Terraform 指定端口似乎是明确的,而不是遗漏。我似乎还看到,指定端口的功能确实存在于 Google 的 REST API 中。

然后我打算建议您通过 Github 提出缺陷,但后来想知道它是否已经存在。我做了一些挖掘,并且已经有对缺失功能的请求:

Allow specifying 'container_port' and 'request_timeout' for google_cloud_run_service

我相信您问题的核心答案会变成:

What you are trying to do should work with Terraform and has been raised as an issue and we must wait for the resolution in the Terraform provider.

关于google-cloud-platform - 想要通过 Terraform 部署 Google Cloud Run 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60693249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com