Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Function trigger_event yields a 400 Bad Request #2409

Closed
hedlund opened this issue Nov 6, 2018 · 6 comments
Closed

Cloud Function trigger_event yields a 400 Bad Request #2409

hedlund opened this issue Nov 6, 2018 · 6 comments
Labels
bug forward/review In review; remove label to forward service/cloudfunctions

Comments

@hedlund
Copy link

hedlund commented Nov 6, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.11.10
+ provider.archive v1.1.0
+ provider.google v1.19.1

Affected Resource(s)

  • google_cloudfunctions_function

Terraform Configuration Files

resource "google_cloudfunctions_function" "func" {
  name                  = "my-trigger-func"
  source_archive_bucket = "my-func-bucket"
  source_archive_object = "my-func.zip"
  entry_point           = "myFunc"

  event_trigger = {
    event_type = "google.storage.object.finalize"
    resource   = "my-trigger-bucket"
  }
}

Debug Output

https://gist.github.com/hedlund/805f28874274090af63fc897cd604229

Expected Behavior

Terraform should've created a cloud function with a Cloud Storage event trigger.

Actual Behavior

I get a 400 bad request.

Steps to Reproduce

If I do not include the event_trigger everything works fine, but I can not get it to work with the trigger.

Looking into the debug logs (linked above) og the actual JSON request, we can see that the resource field on the eventTrigger object gets mangled:

"resource": "%!(EXTRA string=my-project, string=my-trigger-func)"

That should just be a plain resource name. Seeing as the code in the provider uses a function called GetResourceNameFromSelfLink, I have tried using a self_link reference to a bucket resource, as well as various combinations of string names, but nothing works.

The %!(EXTRA field hint that we have some variadic string interpolation that doesn't work as intended.

@ghost ghost added the bug label Nov 6, 2018
@hedlund hedlund changed the title Cloud Function trigger_event does not work Cloud Function trigger_event yields a 400 Bad Request Nov 6, 2018
@hedlund
Copy link
Author

hedlund commented Nov 6, 2018

I debugged this further, and the problem yielding the %!(EXTRA was actually my fault (surprise, surprise).. ;-)

The problem was that I used the event type as described in the Google documentation (that you link to from the Terraform docs):

event_type = "google.storage.object.finalize"

But in order to get the string interpolation to work, we have to define the type using another notation:

event_type = "providers/cloud.storage/eventTypes/object.finalize"

After making that change, the resource is named correctly in the request, but I still get a 400 bad request. However, if I change the event_type to update it works:

event_type = "providers/cloud.storage/eventTypes/object.update"

Curiously enough, object.update is not even listed as a valid trigger in the Google documentation (again, which is linked on the documentation page): https://cloud.google.com/functions/docs/calling/storage

@rileykarson
Copy link
Collaborator

I think I see what's happening here! We only supported the legacy triggers before, and I added support for a more correct syntax but didn't expand the number of triggers we support (since it isn't a breaking change to do so in the future and was constrained by time so we could cut 1.19.0)

To my understanding, the syntax has changed for declaring a trigger from a shape like providers/cloud.storage/eventTypes/object.change for legacy triggers, to google.storage.object.finalize for newer ones.

You're correct that the reference documentation isn't a great fit there - neither is the reference for the field itself, which explains how to shape a legacy request (I think the format you send in a request has changed. I'll verify that as I implement this.)

I'll look into making the Terraform documentation a little clearer, and supporting new-style Cloud Storage triggers right now.

@hedlund
Copy link
Author

hedlund commented Nov 7, 2018

Great! Thank you very much for looking into it, and keep up the great work! :-)

@sebght
Copy link

sebght commented Aug 2, 2019

@rileykarson provider/terraform/website/docs/d/datasource_cloudfunctions_function.html.markdown remains unchanged, which leads to an outdated documentation

@ghost
Copy link

ghost commented Aug 2, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 2, 2019
@rileykarson
Copy link
Collaborator

Spun out #4171 for the docs issue.

@github-actions github-actions bot added service/cloudfunctions forward/review In review; remove label to forward labels Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/cloudfunctions
Projects
None yet
Development

No branches or pull requests

3 participants