Skip to content

Commit

Permalink
Add support for new-style cloud functions triggers. (#91)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
  • Loading branch information
modular-magician authored and nat-henderson committed Dec 6, 2018
1 parent 34972ad commit 0b36131
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions google-beta/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"):
Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_cloudfunctions_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/cloudfunctions_function.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down

0 comments on commit 0b36131

Please sign in to comment.