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:
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"
}
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"
}
}
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 TYPE_UNSPECIFIED
.
Possible values are: TYPE_UNSPECIFIED
, PROTOCOL_BUFFER
, 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. Changes
to the definition commit new schema revisions.
A schema can only have up to 20 revisions, so updates that fail with an
error indicating that the limit has been reached require manually
deleting old revisions.
project
- (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
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}}
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.Schema can be imported using any of these accepted formats:
projects/{{project}}/schemas/{{name}}
{{project}}/{{name}}
{{name}}
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}}
This resource supports User Project Overrides.