![](/img/trans.png)
[英]Google Cloud Run Starts Container Before Healthcheck is Healthy
[英]Google Cloud Functions 2 Terraform fails to deploy (error waiting for creating function, container healthcheck failed)
我按照官方 terraform 文档了解如何创建 google_cloudfunctions2_function 资源,每次部署它都会失败并出现错误
Error: Error waiting to create function: Error waiting for Creating function: Error code 3, message: Could not create or update Cloud Run service ramowka-357-schedule, Container Healthcheck failed. Revision 'ramowka-357-schedule-00001-few' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
在 Google Cloud Console UI 中,我注意到没有为此 function 创建 Eventarc,因此触发器为HTTP
。 当我从 UI 手动编辑 function 并手动添加 Eventarc(与 terraform 中配置的相同发布/订阅主题)时,它会重新部署并运行。
这是我的 tf 代码:
resource "google_cloudfunctions2_function" "default" {
name = var.function_name
location = var.function_location
build_config {
runtime = "python38"
entry_point = var.function_name
source {
storage_source {
bucket = google_storage_bucket.source.name
object = google_storage_bucket_object.zip.name
}
}
}
service_config {
max_instance_count = 1
available_memory = "128Mi"
timeout_seconds = 120
environment_variables = {
USER_EMAIL = var.user_email
SCHEDULE_URL = var.schedule_url
DRY_RUN = var.dry_run
}
}
event_trigger {
trigger_region = var.function_location
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = google_pubsub_topic.default.id
retry_policy = "RETRY_POLICY_RETRY"
}
depends_on = [
google_pubsub_topic.default
]
}
这是我的 function 代码(我非常简单地排除了可能的罪魁祸首代码):
主程序
import functions_framework
@functions_framework.cloud_event
def subscribe(event):
print('test')
要求.txt
functions-framework==3.*
我在 TF 方面缺少任何导致它失败的东西吗?
我发现了问题,它与我在environment_variables
部分中使用的符号有关。 我替换了这个:
USER_EMAIL = var.user_email
SCHEDULE_URL = var.schedule_url
DRY_RUN = var.dry_run
对此
APP_USER_EMAIL = "${var.user_email}"
APP_SCHEDULE_URL = "${var.schedule_url}"
APP_DRY_RUN = "${var.dry_run}"
它奏效了。 在这一点上,我 100% 肯定这是由DRY_RUN
条目引起的(重命名后问题消失了,我一个一个地重命名变量以隔离罪魁祸首)并且我已经针对此行为提交了 Issue: https://issuetracker。 google.com/issues/260596909
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.