Google Cloud Pub/Sub Topic
This page shows how to write Terraform for Cloud Pub/Sub Topic and write them securely.
google_pubsub_topic (Terraform)
The Topic in Cloud Pub/Sub can be configured in Terraform with the resource name google_pubsub_topic. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_pubsub_topic" "bigquery-append-tsv" {
name = "bigquery-append-tsv"
labels = {user = "trellis"}
}
resource "google_pubsub_topic" "bigquery-import-csv" {
resource "google_pubsub_topic" "version_every_minute" {
name = "version_every_minute"
}
resource "google_pubsub_topic" "version_every_two_minutes" {
name = "version_every_two_minutes"
resource "google_pubsub_topic" "taskbuilds" {
name = "taskbuilds"
}
# Create for PubSub Topic for cleanups
# terraform import google_pubsub_topic.cleanups cleanups
resource "google_pubsub_topic" "version_every_minute" {
name = "version_every_minute"
}
resource "google_pubsub_topic" "version_every_two_minutes" {
name = "version_every_two_minutes"
resource "google_pubsub_topic" "foo" {
project = var.project
name = local.foo
}
resource "google_pubsub_subscription" "foo" {
Parameters
-
idoptional computed - string -
kms_key_nameoptional - string
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/'
-
labelsoptional - map from string to string
A set of key/value label pairs to assign to this Topic.
-
namerequired - string
Name of the topic.
-
projectoptional computed - string -
message_storage_policylist block-
allowed_persistence_regionsrequired - list of string
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.
-
-
timeoutssingle block
Explanation in Terraform Registry
A named resource to which messages are sent by publishers. To get more information about Topic, see:
- API documentation
- How-to Guides
- 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_identityresource.
Frequently asked questions
What is Google Cloud Pub/Sub Topic?
Google Cloud Pub/Sub Topic 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 Topic?
For Terraform, the StanfordBioinformatics/trellis-mvp-terraform, chtest0410/tfsample and geosentry/cloud source code examples are useful. See the Terraform Example section for further details.