google_pubsub_topic

A named resource to which messages are sent by publishers.

To get more information about Topic, see:

Open in Cloud Shell

Example Usage - Pubsub Topic Basic

resource "google_pubsub_topic" "example" {
  name = "example-topic"

  labels = {
    foo = "bar"
  }

  message_retention_duration = "86600s"
}
## Example Usage - Pubsub Topic Cmek
resource "google_pubsub_topic" "example" {
  name         = "example-topic"
  kms_key_name = google_kms_crypto_key.crypto_key.id
}

resource "google_kms_crypto_key" "crypto_key" {
  name     = "example-key"
  key_ring = google_kms_key_ring.key_ring.id
}

resource "google_kms_key_ring" "key_ring" {
  name     = "example-keyring"
  location = "global"
}
Open in Cloud Shell

Example Usage - Pubsub Topic Geo Restricted

resource "google_pubsub_topic" "example" {
  name = "example-topic"

  message_storage_policy {
    allowed_persistence_regions = [
      "europe-west3",
    ]
  }
}
## Example Usage - Pubsub Topic Schema Settings
resource "google_pubsub_schema" "example" {
  name = "example"
  type = "AVRO"
  definition = "{\n  \"type\" : \"record\",\n  \"name\" : \"Avro\",\n  \"fields\" : [\n    {\n      \"name\" : \"StringField\",\n      \"type\" : \"string\"\n    },\n    {\n      \"name\" : \"IntField\",\n      \"type\" : \"int\"\n    }\n  ]\n}\n"
}

resource "google_pubsub_topic" "example" {
  name = "example-topic"

  depends_on = [google_pubsub_schema.example]
  schema_settings {
    schema = "projects/my-project-name/schemas/example"
    encoding = "JSON"
  }
}
Open in Cloud Shell

Example Usage - Pubsub Topic Ingestion Kinesis

resource "google_pubsub_topic" "example" {
  name = "example-topic"

  # Outside of automated terraform-provider-google CI tests, these values must be of actual AWS resources for the test to pass.
  ingestion_data_source_settings {
    aws_kinesis {
        stream_arn = "arn:aws:kinesis:us-west-2:111111111111:stream/fake-stream-name"
        consumer_arn = "arn:aws:kinesis:us-west-2:111111111111:stream/fake-stream-name/consumer/consumer-1:1111111111"
        aws_role_arn = "arn:aws:iam::111111111111:role/fake-role-name"
        gcp_service_account = "fake-service-account@fake-gcp-project.iam.gserviceaccount.com"
    }
  }
}

Argument Reference

The following arguments are supported:


The message_storage_policy block supports:

The schema_settings block supports:

The ingestion_data_source_settings block supports:

The aws_kinesis block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Topic can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Topic using one of the formats above. For example:

import {
  id = "projects/{{project}}/topics/{{name}}"
  to = google_pubsub_topic.default
}

When using the terraform import command, Topic can be imported using one of the formats above. For example:

$ terraform import google_pubsub_topic.default projects/{{project}}/topics/{{name}}
$ terraform import google_pubsub_topic.default {{project}}/{{name}}
$ terraform import google_pubsub_topic.default {{name}}

User Project Overrides

This resource supports User Project Overrides.