简体   繁体   中英

Google Cloud Functions 2 Terraform fails to deploy (error waiting for creating function, container healthcheck failed)

I follow official terraform docs on how to create google_cloudfunctions2_function resource and every time I deploy it it fails with error

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.

In Google Cloud Console UI I notice that there is no Eventarc created for this function so the trigger is HTTP . When I manually edit the function from the UI and add Eventarc by hand (same pub/sub topic as configured in terraform) it redeploys and works.

This is my tf code:

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
  ]
}

This is my function code (I made it super simple to exclude code as possible culprit):

main.py

import functions_framework


@functions_framework.cloud_event
def subscribe(event):
    print('test')

requirements.txt

functions-framework==3.*

Anything I am missing on TF side that makes it fail?

I found the issue and it was with notation I used in environment_variables section. I replaced this:

      USER_EMAIL   = var.user_email
      SCHEDULE_URL = var.schedule_url
      DRY_RUN      = var.dry_run

to this

      APP_USER_EMAIL   = "${var.user_email}"
      APP_SCHEDULE_URL = "${var.schedule_url}"
      APP_DRY_RUN      = "${var.dry_run}"

and it worked. At this point I am 100% positive this was caused by DRY_RUN entry (after renaming it the issue is gone, I renamed variable one by one to isolate the culprit) and I've filed Issue for this behavior: https://issuetracker.google.com/issues/260596909

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM