Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Google Cloud Function by Terraform got "Error 400: The request has errors, badRequest"

I want to deploy Cloud Function by Terraform but it fails.

export TF_LOG=DEBUG
terraform init
terraform plan # it does not fail
terraform apply # this fail

{
  "error": {
    "code": 400,
    "message": "The request has errors",
    "errors": [
      {
        "message": "The request has errors",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

What I tired

  • I tried to change the trigger to HTTP but the deployment also failed.
  • enable TF_LOG
  • do terraform plan but it succeeded

terraform template

below is my main.tf file

resource "google_pubsub_topic" "topic" {
  name    = "rss-webhook-topic"
  project = "${var.project_id}"
}


resource "google_cloudfunctions_function" "function" {
  name                = "rss-webhook-function"
  entry_point         = "helloGET"
  available_memory_mb = 256
  project             = "${var.project_id}"

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = "${google_pubsub_topic.topic.name}"
  }

  source_archive_bucket = "${var.bucket_name}"
  source_archive_object = "${google_storage_bucket_object.archive.name}"
}

data "archive_file" "function_src" {
  type        = "zip"
  output_path = "function_src.zip"

  source {
    content  = "${file("src/index.js")}"
    filename = "index.js"
  }
}

resource "google_storage_bucket_object" "archive" {
  name       = "function_src.zip"
  bucket     = "${var.bucket_name}"
  source     = "function_src.zip"
  depends_on = ["data.archive_file.function_src"]
}

environment

Terraform version: 0.11.13
Go runtime version: go1.12 + provider.archive v1.2.2 + provider.google v2.5.1

like image 382
hiroga Avatar asked Jun 06 '26 02:06

hiroga


1 Answers

property "runtime" is required.

below works.

resource "google_cloudfunctions_function" "function" {
  name                = "rss-webhook-function"
  entry_point         = "helloGET"
  available_memory_mb = 256
  project             = "${var.project_id}"
  runtime             = "nodejs8"

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = "${google_pubsub_topic.topic.name}"
  }

  source_archive_bucket = "${var.bucket_name}"
  source_archive_object = "${google_storage_bucket_object.archive.name}"
}


like image 176
hiroga Avatar answered Jun 10 '26 19:06

hiroga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!