blob: 622210ed41d7ab8c1618f8fac24e50d003b9fcde [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** 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 named resource to which messages are sent by publishers.
---
# google\_pubsub\_topic
A named resource to which messages are sent by publishers.
To get more information about Topic, see:
* [API documentation](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)
* How-to Guides
* [Managing Topics](https://cloud.google.com/pubsub/docs/admin#managing_topics)
~> **Note:** You can retrieve the email of the Google Managed Pub/Sub Service Account used for forwarding
by using the `google_project_service_identity` resource.
<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_working_dir=pubsub_topic_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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 Topic Basic
```hcl
resource "google_pubsub_topic" "example" {
name = "example-topic"
labels = {
foo = "bar"
}
message_retention_duration = "86600s"
}
```
## Example Usage - Pubsub Topic Cmek
```hcl
resource "google_pubsub_topic" "example" {
name = "example-topic"
kms_key_name = google_kms_crypto_key.crypto_key.id
}
resource "google_kms_crypto_key" "crypto_key" {
name = "example-key"
key_ring = google_kms_key_ring.key_ring.id
}
resource "google_kms_key_ring" "key_ring" {
name = "example-keyring"
location = "global"
}
```
<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_working_dir=pubsub_topic_geo_restricted&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" 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 Topic Geo Restricted
```hcl
resource "google_pubsub_topic" "example" {
name = "example-topic"
message_storage_policy {
allowed_persistence_regions = [
"europe-west3",
]
}
}
```
## Example Usage - Pubsub Topic Schema Settings
```hcl
resource "google_pubsub_schema" "example" {
name = "example"
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_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)
Name of the topic.
- - -
* `kms_key_name` -
(Optional)
The resource name of the Cloud KMS CryptoKey to be used to protect access
to messages published on this topic. Your project's PubSub service account
(`service-{{PROJECT_NUMBER}}@gcp-sa-pubsub.iam.gserviceaccount.com`) must have
`roles/cloudkms.cryptoKeyEncrypterDecrypter` to use this feature.
The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`
* `labels` -
(Optional)
A set of key/value label pairs to assign to this Topic.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field `effective_labels` for all of the labels present on the resource.
* `message_storage_policy` -
(Optional)
Policy constraining the set of Google Cloud Platform regions where
messages published to the topic may be stored. If not present, then no
constraints are in effect.
Structure is [documented below](#nested_message_storage_policy).
* `schema_settings` -
(Optional)
Settings for validating messages published against a schema.
Structure is [documented below](#nested_schema_settings).
* `message_retention_duration` -
(Optional)
Indicates the minimum duration to retain a message after it is published
to the topic. If this field is set, messages published to the topic in
the last messageRetentionDuration are always available to subscribers.
For instance, it allows any attached subscription to seek to a timestamp
that is up to messageRetentionDuration in the past. If this field is not
set, message retention is controlled by settings on individual subscriptions.
The rotation period has the format of a decimal number, followed by the
letter `s` (seconds). Cannot be more than 31 days or less than 10 minutes.
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
<a name="nested_message_storage_policy"></a>The `message_storage_policy` block supports:
* `allowed_persistence_regions` -
(Required)
A list of IDs of GCP regions where messages that are published to
the topic may be persisted in storage. Messages published by
publishers running in non-allowed GCP regions (or running outside
of GCP altogether) will be routed for storage in one of the
allowed regions. An empty list means that no regions are allowed,
and is not a valid configuration.
<a name="nested_schema_settings"></a>The `schema_settings` block supports:
* `schema` -
(Required)
The name of the schema that messages published should be
validated against. Format is projects/{project}/schemas/{schema}.
The value of this field will be _deleted-schema_
if the schema has been deleted.
* `encoding` -
(Optional)
The encoding of messages validated against schema.
Default value is `ENCODING_UNSPECIFIED`.
Possible values are: `ENCODING_UNSPECIFIED`, `JSON`, `BINARY`.
## 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}}/topics/{{name}}`
* `terraform_labels` -
The combination of labels configured directly on the resource
and default labels configured on the provider.
* `effective_labels` -
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
## 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
Topic can be imported using any of these accepted formats:
* `projects/{{project}}/topics/{{name}}`
* `{{project}}/{{name}}`
* `{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Topic using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/topics/{{name}}"
to = google_pubsub_topic.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Topic can be imported using one of the formats above. For example:
```
$ terraform import google_pubsub_topic.default projects/{{project}}/topics/{{name}}
$ terraform import google_pubsub_topic.default {{project}}/{{name}}
$ terraform import google_pubsub_topic.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).