blob: bd8329829bff366f07938111887374a7266f41f3 [file] [log] [blame] [edit]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Cloud Pub/Sub"
description: |-
A schema is a format that messages must follow,
creating a contract between publisher and subscriber that Pub/Sub will enforce.
---
# 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:
* [API documentation](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas)
* How-to Guides
* [Creating and managing schemas](https://cloud.google.com/pubsub/docs/schemas)
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=pubsub_schema_basic&open_in_editor=main.tf" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Pubsub Schema Basic
```hcl
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
```hcl
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:
* `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](https://cloud.google.com/pubsub/docs/commit-schema-revision).
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](https://cloud.google.com/pubsub/docs/delete-schema-revision).
* `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](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
- `create` - Default is 20 minutes.
- `update` - Default is 20 minutes.
- `delete` - Default is 20 minutes.
## Import
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](https://developer.hashicorp.com/terraform/language/import) to import Schema using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/schemas/{{name}}"
to = google_pubsub_schema.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).