google-cloud-platformgoogle-cloud-functionsgoogle-deployment-manager

Turn `gcloud beta functions deploy` command into a Deployment Manager template with a FailurePolicy


I'm running this command:

gcloud beta functions deploy myfunc \
--entry-point handler \
--project my-project \
--runtime python37 \
--trigger-resource 'gs://my-bucket' \
--trigger-event google.storage.object.finalize

How do I specify xxx and xxx in the Jinja template? Looks like I have to use EventTrigger in the template, but I am not sure how that is formatted?

resources:
  - name: resource-name
    type: 'gcp-types/cloudfunctions-v1:projects.locations.functions'
    properties:
      function: test
      parent: projects/my-project/locations/us-central1
      location: us-central1
      sourceArchiveUrl: 'gs://my-project-bucket/sdfsd.zip'
      runtime: python37
      entryPoint: handler
      maxInstances: 10
      timeout: 30s
      availableMemoryMb: 64
      eventTrigger: ????

Is there a full example of an EventTrigger specified in YAML that includes a FailurePolicy?

Documentation doesn't make this very clear: https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions#FailurePolicy

Not sure what this is suppose to look like in the yaml template:

enter image description here

This works for setting a failurePolicy in Jinja:

  ...
  eventTrigger:
    ...
    failurePolicy:
      retry: {}

Pretty wonky but to disable you just don't specify it:

{% if properties['failurePolicy'] %}
 failurePolicy:
  retry: {}
{% endif %}

Solution

  • Deployment Manager has some specific examples on Github. Here's an example of an eventTrigger with Cloud Pub/Sub:

    eventTrigger:
      resource: $(ref.my-topic.name)
      eventType: providers/cloud.pubsub/eventTypes/topic.publish
    

    For a FailurePolicy, I would try adding this:

    eventTrigger:
      ...
      failurePolicy:
        retry: true
    

    Reference: