Terraform部署Google Cloud Function出现“错误400:请求有错误,badRequest”

时间:2019-05-04 01:38:43

标签: google-cloud-platform google-cloud-functions

我想通过Terraform部署Cloud Function,但是失败。

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

我累了

  • 我尝试将触发器更改为HTTP,但是部署也失败了。
  • 启用TF_LOG
  • terraform plan但成功了

地形模板

下面是我的main.tf文件

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

环境

Terraform版本:0.11.13
Go运行时版本:go1.12 + provider.archive v1.2.2 + provider.google v2.5.1

1 个答案:

答案 0 :(得分:0)

需要属性“运行时”。

在下面工作。

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