# Google Cloud Pub/Sub Destination Config Reference


> Complete Rudder CLI reference for the Google Cloud Pub/Sub destination config keys, topic and attribute mapping, source types, and secrets.



[Google Cloud Pub/Sub](https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/) is a streaming destination. RudderStack publishes each event as a JSON message to the Pub/Sub topic its name or type maps to, optionally with message attributes copied from the event.

In a Google Cloud Pub/Sub destination spec:

- `type: googlepubsub`
- `definition_version: 1`

## Sample configuration

```yaml
version: rudder/v1
kind: destination
metadata:
  name: pubsub-prod
spec:
  id: pubsub-prod
  display_name: PubSub Production
  type: googlepubsub
  definition_version: 1
  enabled: true
  config:
    project_id: acme-analytics
    credentials: '{{ .PUBSUB_CREDENTIALS }}'

    event_to_topic_map:
      - from: Order Completed
        to: rudder-orders
      - from: identify
        to: rudder-users
      - from: "*"
        to: rudder-events
    event_to_attribute_map:
      - from: Order Completed
        to: order_id
      - from: Order Completed
        to: currency

    connection_mode:
      web: cloud
      cloud: cloud
    consent_management:
      web:
        - provider: oneTrust
          consents:
            - analytics
```

The above example sends `Order Completed` and `identify` events to their own topics, and every other event to `rudder-events` — see [Topic mapping](#topic-mapping). `credentials` is JSON, so its reference is single-quoted — see [Secrets](#secrets).

## Config keys

`config` accepts only the keys listed below. The [shared config key rules](https://www.rudderstack.com/docs/rudder-cli/destination-types/#config-key-rules) cover unknown keys, defaults, and immutability.

### Connection

<div class="rs-ckeys">
<div class="rs-ckey" id="project_id">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">project_id</p>Required</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  ID of the GCP project that holds the topics.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>At most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted by <code>validate</code>, but RudderStack connects with the project ID as written, so use a literal.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="credentials">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">credentials</p>RequiredSecret</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Contents of the JSON key file for a GCP service account with the <strong>Pub/Sub Publisher</strong> role on the topics.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Only checked for presence locally. RudderStack accepts only a service account key — any other kind of Google credential fails at delivery.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <p>Supply it as a <code>{{ .VAR }}</code> reference rather than a literal — see <a href="#secrets" >Secrets</a>.</p>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#get-started" >Get started</a> for creating the service account and its key.</p>

</div>

</div>

</div>

### Topic mapping

Each event is matched against the `from` field of both mappings by its event name first, then by its type — `track`, `page`, `identify`, and so on — then by `*`, which matches every event. Matching ignores case.

<div class="rs-ckeys">
<div class="rs-ckey" id="event_to_topic_map">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">event_to_topic_map</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>array of objects</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Maps events to the topics RudderStack publishes them to.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>from</code> — an event name, an event type, or <code>*</code>.</li>
<li><code>to</code> — ID of the topic, exactly as it appears in Pub/Sub. Topic IDs are case-sensitive.</li>
<li>Each field is at most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted by <code>validate</code> in either field, but RudderStack prepares a publisher for each <code>to</code> value as written, so keep <code>to</code> literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <p>Rudder CLI doesn&rsquo;t require this key, but an event that matches no entry isn&rsquo;t delivered. Map <code>*</code> to send everything else to one topic:</p>
<div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">event_to_topic_map:
  - from: Order Completed
    to: rudder-orders
  - from: &#34;*&#34;
    to: rudder-events</code></pre></div>
</div><p>Quote <code>&quot;*&quot;</code> — unquoted, YAML reads it as an alias and the spec fails to parse.</p>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#how-does-event-mapping-work-with-the-topic-id" >How does event mapping work with the topic ID?</a>.</p>

</div>

</div>

<div class="rs-ckey" id="event_to_attribute_map">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">event_to_attribute_map</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>array of objects</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Adds message attributes copied from the event. Each entry names a field whose value RudderStack attaches as an attribute.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>from</code> — an event name, an event type, or <code>*</code>, matched as described above. Only one set of entries applies to an event: those for its name, or else its type, or else <code>*</code>.</li>
<li><code>to</code> — path of the field, in dot notation. RudderStack looks it up at the event&rsquo;s root, then in <code>properties</code>, <code>traits</code>, and <code>context.traits</code>. The attribute takes the last segment of the path as its name, so <code>metadata.order_id</code> becomes <code>order_id</code>.</li>
<li>Repeat a <code>from</code> to attach several attributes. A field the event doesn&rsquo;t carry adds no attribute.</li>
<li>Attribute values are strings. A number or boolean is converted, and an object or array is sent as JSON.</li>
<li>Each field is at most 100 characters, and must not contain line breaks. Both accept a <code>{{ path || fallback }}</code> template in place of a literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">event_to_attribute_map:
  - from: Order Completed
    to: order_id
  - from: Order Completed
    to: metadata.coupon</code></pre></div>
</div><p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#attributes" >Attributes</a>.</p>
</div>

</div>

</div>

### Per-source keys

Both keys are objects keyed by the local source type — the tokens listed under [Source types](#source-types). A key naming a source type this destination doesn't support fails validation.

<div class="rs-ckeys">
<div class="rs-ckey" id="connection_mode">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">connection_mode</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Maps each source type you connect to the mode its events reach Pub/Sub in, using the modes in <a href="#source-types" >Source types</a>.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>An entry is required for each source type you connect — see <a href="#connect-a-source" >Connect a source</a>.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">connection_mode:
  web: cloud
  cloud: cloud</code></pre></div>
</div>
</div>

</div>

<div class="rs-ckey" id="consent_management">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">consent_management</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Consent provider configuration per source type. The entry shape, accepted providers, and the rules on <code>resolution_strategy</code> and <code>consents</code> are shared across all destination types — see <a href="https://www.rudderstack.com/docs/rudder-cli/destination-types/#consent-management" >Consent management</a>.
</p>

</div>

</div>

## Source types

Google Cloud Pub/Sub accepts events from these source types in the mentioned connection modes:

| Source type | Connection mode |
| :-----| :-----|
| `android` | `cloud` |
| `android_kotlin` | `cloud` |
| `ios` | `cloud` |
| `ios_swift` | `cloud` |
| `web` | `cloud` |
| `unity` | `cloud` |
| `react_native` | `cloud` |
| `flutter` | `cloud` |
| `cordova` | `cloud` |
| `cloud` | `cloud` |
| `warehouse` | `cloud` |

Every source type is `cloud` only — events reach the topics from RudderStack's servers, never in device mode.

`warehouse` is the token a [Reverse ETL source](https://www.rudderstack.com/docs/sources/reverse-etl/) resolves to. Rudder CLI manages the destination’s `warehouse` entry — if the destination is connected to a Reverse ETL source, set `connection_mode.warehouse: cloud` in its spec, or `apply` removes it.

Rudder CLI can also declare the Reverse ETL connection itself, for the types listed under [Supported destinations](https://www.rudderstack.com/docs/rudder-cli/yaml-retl-connections/#supported-destinations) — see [Manage Reverse ETL Connections using Rudder CLI](https://www.rudderstack.com/docs/rudder-cli/retl-connections/).

**Info:** The dashboard additionally offers Google Cloud Pub/Sub to AMP and Shopify sources. Rudder CLI doesn&#39;t manage those connections, so `amp` and `shopify` are invalid here.

## Connect a source

An event stream connection to this destination is checked against two rules at `validate` time.

**The source's type must be supported.** A source's type resolves to one of the tokens above before the check — a JavaScript source resolves to `web`, and webhook and server-side SDK sources resolve to `cloud`. Every type an event stream source can resolve to is supported here, so this check always passes.

**The destination config must carry a `connection_mode` entry for that source type.** This lives on the destination spec, not on the [connection spec](https://www.rudderstack.com/docs/rudder-cli/yaml-connections/). Without it:

```text
destination 'pubsub-prod' config has no 'connection_mode' entry for source type 'web'
```

Google Cloud Pub/Sub needs no additional config keys to connect a source of any type.

## Secrets

`credentials` is the only secret key. Write it as a `{{ .VAR }}` reference and supply the value at apply time:

```yaml
config:
  credentials: '{{ .PUBSUB_CREDENTIALS }}'
```

```bash
export RUDDER_PUBSUB_CREDENTIALS="$(cat service-account.json)"
rudder-cli apply

# or
rudder-cli apply --var-file secrets.vars.yaml
```

Note that:

- `credentials` is JSON, so write its reference in single quotes, as above. Rudder CLI pastes the value into the YAML before parsing it, and the JSON's double quotes would end a double-quoted string.
- `rudder-cli import` writes only the secrets the API returns, as `{{ .VAR }}` references, and leaves the others out. Add any secret key it leaves out, then supply the variables before you apply — see [Secrets](https://www.rudderstack.com/docs/rudder-cli/destination-types/#secrets).

See [How to Use Variable Substitution in Rudder CLI](https://www.rudderstack.com/docs/rudder-cli/variable-substitution/).

## Changes by release

<p>No changes since this type became available.</p>

For changes across every destination type, see [Destination Type Changes by Release](https://www.rudderstack.com/docs/rudder-cli/destination-types/changes/).

## See more

- [Google Pub/Sub Destination](https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/) for service account setup, topic mapping, and attributes
- [Destination Type Reference for Rudder CLI](https://www.rudderstack.com/docs/rudder-cli/destination-types/) for the rules shared across destination types
- [Destination YAML Reference](https://www.rudderstack.com/docs/rudder-cli/yaml-destinations/) for the spec envelope

