Skip to content

GCP PubSub

udx-github edited this page Jul 26, 2026 · 1 revision

Creates a Pub/Sub topic with push and pull subscriptions.

Use this module when a Rabbit service needs asynchronous messaging - queueing work for Cloud Run services, fanning out events, or buffering bursts with retry and dead-letter policies.

Supported Features

  • One topic per module instance with optional labels and retention.
  • Push subscriptions with OIDC-authenticated delivery to Cloud Run.
  • Pull subscriptions for polling consumers.
  • Per-subscription ack deadline, retry policy, dead-letter policy, and expiration TTL.

Prerequisites

  • GCP credentials with permission to manage Pub/Sub (roles/pubsub.admin).
  • The pubsub.googleapis.com API enabled on the project (enabled automatically via google_api_name).
  • For OIDC push to Cloud Run: the oidc_service_account must hold roles/run.invoker on the target service (see the gcp-cloud-run module's invokers).

Important Notes

  • A subscription is push when push_endpoint is set, pull otherwise.
  • dead_letter.topic references an existing topic by name in the same project; this module does not create the DLQ topic. The Pub/Sub service agent needs publish rights on the DLQ topic and subscribe rights on the subscription.
  • Deleted subscription names cannot be reused immediately; prefer stable names.
  • expiration_ttl removes idle subscriptions; omit it for durable subscriptions.

Minimal Example

services:
  - name: "Eventing"
    module: "gcp-pubsub"
    id: "my-queue"
    configurations:
      topic_name: "my-topic"
      subscriptions:
        - name: "worker-sub"
          push_endpoint: "https://my-worker-123.us-central1.run.app"
          oidc_service_account: "sa-invoker@my-project.iam.gserviceaccount.com"
          ack_deadline: 60

Outputs

Output Description
topic_id Fully-qualified topic ID.
topic_name Topic name.
subscription_names Map of subscription keys to subscription names.

Full Configuration Schema

configurations:
  topic_name: ""                      # Required. Topic name, unique per project.
  labels: {}                          # Optional. Labels applied to the topic.
  message_retention_duration: ""      # Optional. e.g. "86400s". Omit for default.

  subscriptions:                      # Optional. List of subscriptions on the topic.
    - name: ""                        # Required. Subscription name, unique per project.
      push_endpoint: ""               # Optional. HTTPS endpoint; presence makes this a push subscription.
      oidc_service_account: ""        # Optional. SA email used to mint OIDC tokens for push delivery.
      ack_deadline: 10                # Optional. Seconds (10-600).
      labels: {}                      # Optional. Labels applied to the subscription.
      message_retention_duration: ""  # Optional. e.g. "604800s".
      retain_acked_messages: false    # Optional.
      retry_policy:                   # Optional. Exponential backoff between delivery attempts.
        minimum_backoff: "10s"
        maximum_backoff: "600s"
      dead_letter:                    # Optional. Existing topic to route failed deliveries to.
        topic: ""                     # Topic name in the same project.
        max_delivery_attempts: 5      # 5-100.
      expiration_ttl: ""              # Optional. e.g. "2678400s". Omit for a never-expiring subscription.

Clone this wiki locally