【问题标题】:Deploying Google Cloud Function by Terraform got "Error 400: The request has errors, badRequest"通过 Terraform 部署 Google Cloud Function 得到“错误 400:请求有错误,badRequest”
【发布时间】:2019-05-04 01:38:43
【问题描述】:

我想通过 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

【问题讨论】:

  • 这是在哪里定义的google_pubsub_topic.topic.name
  • 我编辑我的帖子。原始模板具有可以部署的主题。
  • 我不确定您所说的“原始模板具有可以部署的主题”。你是说它现在可以工作了吗?
  • 起初我将主题添加到模板并部署。有效。之后,我将 Cloud Functions 添加到模板中,但部署失败。

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


【解决方案1】:

需要属性“运行时”。

下面的作品。

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


【讨论】:

    猜你喜欢
    • 2020-01-20
    • 2012-07-26
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2018-11-27
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多