How do I build a GCP Pub/Sub topic?
To create a Google Cloud Pub/Sub topic, we need to set up a few basic resources. The first resource defines the project where the topic will be created, and the second resource defines the Pub/Sub topic itself.
Here’s an example of how to create a Google Cloud Pub/Sub topic:
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const exampleTopic = new gcp.pubsub.Topic("example_topic", {name: "my-topic"});
export const topicName = exampleTopic.name;
export const topicProject = exampleTopic.project;
Let’s break down what each part of the code does:
Provider Configuration: This configures the Google Cloud provider with the project and region. You’ll need to replace
my-gcp-project
with your actual Google Cloud project ID.Pub/Sub Topic Resource: This creates a Pub/Sub topic named
my-topic
. You can changemy-topic
to any name that suits your needs.Outputs: These export the names of the created Pub/Sub topic and the project in which it was created, which can be useful for referencing this topic in other parts of your infrastructure.
In summary, we’ve created a simple setup to define a Pub/Sub topic on Google Cloud, configured the provider, instantiated the topic resource, and provided outputs for easy reference in other parts of your infrastructure.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.