From 0b361318a900ae09a0a843c5f217a2200e5893ae Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 6 Nov 2018 09:30:20 -0800 Subject: [PATCH] Add support for new-style cloud functions triggers. (#91) /cc @rileykarson --- google-beta/resource_cloudfunctions_function.go | 5 +++++ google-beta/resource_cloudfunctions_function_test.go | 4 ++-- website/docs/r/cloudfunctions_function.html.markdown | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/google-beta/resource_cloudfunctions_function.go b/google-beta/resource_cloudfunctions_function.go index 7ee4f7ab5e..2a793e8d7e 100644 --- a/google-beta/resource_cloudfunctions_function.go +++ b/google-beta/resource_cloudfunctions_function.go @@ -607,6 +607,11 @@ func expandEventTrigger(configured []interface{}, project string) *cloudfunction eventType := data["event_type"].(string) shape := "" switch { + case strings.HasPrefix(eventType, "google.storage.object."): + shape = "projects/%s/buckets/%s" + case strings.HasPrefix(eventType, "google.pubsub.topic."): + shape = "projects/%s/topics/%s" + // Legacy style triggers case strings.HasPrefix(eventType, "providers/cloud.storage/eventTypes/"): shape = "projects/%s/buckets/%s" case strings.HasPrefix(eventType, "providers/cloud.pubsub/eventTypes/"): diff --git a/google-beta/resource_cloudfunctions_function_test.go b/google-beta/resource_cloudfunctions_function_test.go index 96f99d6893..8f027cbcb7 100644 --- a/google-beta/resource_cloudfunctions_function_test.go +++ b/google-beta/resource_cloudfunctions_function_test.go @@ -637,7 +637,7 @@ resource "google_cloudfunctions_function" "function" { timeout = 61 entry_point = "helloGCS" event_trigger { - event_type = "providers/cloud.storage/eventTypes/object.change" + event_type = "google.storage.object.finalize" resource = "${google_storage_bucket.bucket.name}" failure_policy { retry = true @@ -667,7 +667,7 @@ resource "google_cloudfunctions_function" "function" { timeout = 61 entry_point = "helloGCS" event_trigger { - event_type = "providers/cloud.storage/eventTypes/object.change" + event_type = "google.storage.object.finalize" resource = "${google_storage_bucket.bucket.name}" } }`, bucketName, zipFilePath, functionName) diff --git a/website/docs/r/cloudfunctions_function.html.markdown b/website/docs/r/cloudfunctions_function.html.markdown index d733408482..df76f9095a 100644 --- a/website/docs/r/cloudfunctions_function.html.markdown +++ b/website/docs/r/cloudfunctions_function.html.markdown @@ -85,9 +85,11 @@ Deprecated. Use `event_trigger.failure_policy.retry` instead. The `event_trigger` block supports: -* `event_type` - (Required) The type of event to observe. For example: `"providers/cloud.storage/eventTypes/object.change"` - and `"providers/cloud.pubsub/eventTypes/topic.publish"`. See the documentation on [calling Cloud Functions](https://cloud.google.com/functions/docs/calling/) - for a full reference. Only Cloud Storage and Cloud Pub/Sub triggers are supported at this time. +* `event_type` - (Required) The type of event to observe. For example: `"google.storage.object.finalize"`. +See the documentation on [calling Cloud Functions](https://cloud.google.com/functions/docs/calling/) for a full reference. +Only Cloud Storage and Cloud Pub/Sub triggers are supported at this time. +Legacy Cloud Storage and Cloud Pub/Sub triggers are also supported, such as `"providers/cloud.storage/eventTypes/object.change"` +and `"providers/cloud.pubsub/eventTypes/topic.publish"`. * `resource` - (Required) Required. The name of the resource from which to observe events, for example, `"myBucket"`