Skip to content

googlePubsubSchema

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:

Example Usage - Pubsub Schema Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.pubsubSchema.PubsubSchema(this, "example", {
  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',
  name: "example",
  type: "AVRO",
});

Example Usage - Pubsub Schema Protobuf

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googlePubsubSchemaExample = new google.pubsubSchema.PubsubSchema(
  this,
  "example",
  {
    definition:
      'syntax = "proto3";\nmessage Results {\nstring message_request = 1;\nstring message_response = 2;\nstring timestamp_request = 3;\nstring timestamp_response = 4;\n}',
    name: "example",
    type: "PROTOCOL_BUFFER",
  }
);
const googlePubsubTopicExample = new google.pubsubTopic.PubsubTopic(
  this,
  "example_1",
  {
    depends_on: [`\${${googlePubsubSchemaExample.fqn}}`],
    name: "example-topic",
    schema_settings: [
      {
        encoding: "JSON",
        schema: "projects/my-project-name/schemas/example",
      },
    ],
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googlePubsubTopicExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) The ID to use for the schema, which will become the final component of the schema's resource name.

  • type - (Optional) The type of the schema definition Default value is typeUnspecified. Possible values are typeUnspecified, protocolBuffer, and avro.

  • definition - (Optional) The definition of the schema. This should contain a string representing the full definition of the schema that is a valid schema definition of the type specified in type.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/schemas/{{name}}

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Schema can be imported using any of these accepted formats:

$ 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.