https://pulumi.com logo
Title
b

bland-florist-21412

05/27/2021, 4:29 PM
I'm still struggling to get a GCP cloud function with a pubsub trigger to work . See https://pulumi-community.slack.com/archives/C84L4E3N1/p1622077138338500 above. In desperation I manually created one and then did a
pulumi import
to see how to do it. I got the following:
import pulumi
import pulumi_gcp as gcp

generate_highlight = gcp.cloudfunctions.Function("generateHighlight",
    available_memory_mb=4096,
    entry_point="generateHighlight",
    ingress_settings="ALLOW_ALL",
    labels={
        "deployment-tool": "console-cloud",
    },
    max_instances=0,
    name="generateHighlight",
    runtime="nodejs12",
    source_archive_bucket="companion-cloud-functions-prod",
    source_archive_object="generateHighlight-9465c8d",
    timeout=60,
    opts=pulumi.ResourceOptions(protect=True))
Note that the pubsub trigger which is set on the function is not mentioned here. But the docs says to use
event_trigger
on the
Function
constructor to set up the trigger. Any help would be very much appreciated.
b

billowy-army-68599

05/27/2021, 4:58 PM
hey Oliver, sorry you're not getting much help here - unfortunately I'm not super familiar with these functions/workflow, but perhaps you might get some assistance on stackOverflow?
i hate to direct your somewhere else, so I'll see if I can figure something out later today
b

bland-florist-21412

05/27/2021, 5:21 PM
I think I might have just figured it out. The
eventType
should be
google.pubsub.topic.publish
instead of
providers/cloud.pubsub/eventTypes/topic.publish
. The docs here: https://www.pulumi.com/docs/reference/pkg/gcp/cloudfunctions/function/#functioneventtrigger send you to the docs here: https://cloud.google.com/functions/docs/calling/pubsub. In those docs they show the current way, which doesn't match the Resource in Pulumi, and the legacy way which does match the Resource but uses the wrong trigger.
A nicer error message would be dandy though I think you're just showing what Google sent you so that seems hard 😞
b

billowy-army-68599

05/27/2021, 5:25 PM
would you be able to post the full example if it's working, or DM it to me? I'd love to create an example to refer to for others
b

bland-florist-21412

05/31/2021, 5:52 PM
I'd be happy to but the code I have to do this isn't super simple because I've set up a "self deploy" system where the code for a cloud function can have a
deploy.yml
file in it's directory and we auto-discover that, build the function from it, determine the trigger type from it, etc. so there's some yml parsing,
if
statements, etc.
The important bit of code is this however:
trigger_args = gcp.cloudfunctions.FunctionEventTriggerArgs(
            event_type='google.pubsub.topic.publish',
            resource=topic.id)
        function_args['event_trigger'] = trigger_args