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

main.tf#L1
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"
}

schemas.tf#L1
resource "google_pubsub_schema" "events_schema1" {
  name       = "events-schema"
  type       = "AVRO"
  definition = file("./events-schema.json")
}
schemas.tf#L1
resource "google_pubsub_schema" "events_schema1" {
  name       = "events-schema"
  type       = "AVRO"
  definition = file("./events-schema.json")
}

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

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 is TYPE_UNSPECIFIED. Possible values are TYPE_UNSPECIFIED, PROTOCOL_BUFFER, 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.

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]]

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:

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.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.