Google Cloud Pub/Sub Schema
This page shows how to write Terraform for Cloud Pub/Sub Schema and write them securely.
google_pubsub_schema (Terraform)
The Schema in Cloud Pub/Sub can be configured in Terraform with the resource name google_pubsub_schema
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_pubsub_schema" "schema" {
name = var.schema_name
type = var.schema_type
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" "events_schema1" {
name = "events-schema"
type = "AVRO"
definition = file("./events-schema.json")
}
resource "google_pubsub_schema" "events_schema1" {
name = "events-schema"
type = "AVRO"
definition = file("./events-schema.json")
}
Parameters
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 isTYPE_UNSPECIFIED
. Possible values areTYPE_UNSPECIFIED
,PROTOCOL_BUFFER
, andAVRO
.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.
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with formatprojects/[[project]]/schemas/[[name]]
Explanation in Terraform Registry
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:
- API documentation
- How-to Guides
Frequently asked questions
What is Google Cloud Pub/Sub Schema?
Google Cloud Pub/Sub Schema is a resource for Cloud Pub/Sub of Google Cloud Platform. Settings can be wrote in Terraform.
Where can I find the example code for the Google Cloud Pub/Sub Schema?
For Terraform, the gauravrao08/gcp, yurikrupnik/mussia12 and yurikrupnik/mussia8 source code examples are useful. See the Terraform Example section for further details.