def create_pubsub_notification(context, depends_on, status_string):
  """Creates a resource to publish a message upon deployment completion.

  Arguments:
      context: the DM context object.
      depends_on: a list of resource names this notification should depend on.
      status_string: the "status" attribute value to publish, e.g. 'STARTED' or
        'COMPLETED'.

  Returns:
    A list of pubsub Deployment Manager actions.
  """

  return [{
    'name': 'pubsub-notification-{}'.format(status_string),
    'action': 'gcp-types/pubsub-v1:pubsub.projects.topics.publish',
    'properties': {
      'topic':
        context.properties['pubsubTopic'],
      'messages': [{
        'attributes': {
          'projectId': context.properties['projectId'],
          'status': status_string,
        }
      }]
    },
    'metadata': {
      # The notification should only run after *all* project-related
      # resources have been deployed.
      'dependsOn': depends_on,
      # Only trigger the pubsub message when the deployment is created (not on
      # update or delete).
      'runtimePolicy': ['UPDATE_ALWAYS'],
    },
  }]