google_pubsub_schema

A schema is a format that messages must follow, creating a contract between publisher and subscriber that Pub/Sub will enforce.

To get more information about Schema, see:

Open in Cloud Shell

Example Usage - Pubsub Schema Basic

resource "google_pubsub_schema" "example" {
  name = "example-schema"
  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"
}

Example Usage - Pubsub Schema Protobuf

resource "google_pubsub_schema" "example" {
  name = "example"
  type = "PROTOCOL_BUFFER"
  definition = "syntax = \"proto3\";\nmessage Results {\nstring message_request = 1;\nstring message_response = 2;\nstring timestamp_request = 3;\nstring timestamp_response = 4;\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"
  }
}

Argument Reference

The following arguments are supported:


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

Schema can be imported using any of these accepted formats:

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

import {
  id = "projects/{{project}}/schemas/{{name}}"
  to = google_pubsub_schema.default
}

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

$ terraform import google_pubsub_schema.default projects/{{project}}/schemas/{{name}}
$ terraform import google_pubsub_schema.default {{project}}/{{name}}
$ terraform import google_pubsub_schema.default {{name}}

User Project Overrides

This resource supports User Project Overrides.