trigger_topic 不适用于 terraform 资源 google_cloudfunctions_function

Pri*_*tel 4 terraform google-cloud-functions

我为 terraform 定义了以下资源来创建云函数。我希望能够通过 pubsub 消息触发它。
我该使用哪一个块?event_trigger或trigger_topic

resource "google_cloudfunctions_function" "function" {

    name                      = var.appname
    entry_point               = "entry"
    available_memory_mb       = 128
    timeout                   = 120
    project                   = var.gcpproject
    region                    = var.region
    #trigger_topic             = "projects/${var.gcpproject}/topics/cloud-builds-topic"**
    source_archive_bucket     = var.google_storage_bucket
    source_archive_object     = "code/${var.appname}.zip"
    runtime     = "python3.7"
   #event_trigger = {
   #   event_type= "google.pubsub.topic.publish"
   #   resource= "projects/${var.gcpproject}/topics/cloud-builds-topic"
   #   service= "pubsub.googleapis.com"
   #   failure_policy= {}
   # }
}
Run Code Online (Sandbox Code Playgroud)

当我使用trigger_topic时,出现错误

Error: Unsupported argument

  on main.tf line 12, in resource "google_cloudfunctions_function" "function":
  12:     trigger_topic             = "projects/${var.gcpproject}/topics/cloud-builds-topic"

An argument named "trigger_topic" is not expected here.
Run Code Online (Sandbox Code Playgroud)

当我使用 event_trigger 时,它会出错

Error: Unsupported argument

  on main.tf line 16, in resource "google_cloudfunctions_function" "function":
  16:     event_trigger = {

An argument named "event_trigger" is not expected here. Did you mean to define
a block of type "event_trigger"?
Run Code Online (Sandbox Code Playgroud)

Mar*_*cin 11

没有这样的属性或trigger_topicgoogle_cloudfunctions_function的属性或块。

event_trigger应该是一个block,而不是一个 map (否=):

   event_trigger {
      event_type= "google.pubsub.topic.publish"
      resource= "projects/${var.gcpproject}/topics/cloud-builds-topic"
      service= "pubsub.googleapis.com"
      #failure_policy= {}
   }
Run Code Online (Sandbox Code Playgroud)

failure_policy也是一个块,而不是地图。service似乎不是event_trigger块中的正确属性。请仔细检查有关有效属性和块的文档。

  • 非常感谢@marcin,我删除了 event_trigger 之后的=,还删除了“service=..”,它有效! (2认同)