How do I create a GCP Pub/Sub Topic IAM Binding with Pulumi?
In this guide, we will create a Google Cloud Pub/Sub Topic and an IAM Binding using Pulumi in TypeScript. This setup will allow you to manage access control to your Pub/Sub topics by specifying which members have particular roles.
Key Points
- Google Cloud Pub/Sub Topic: This is the resource that represents a Pub/Sub topic where messages can be published.
- IAM Binding: This resource binds a role to a list of members, defining who has what type of access to the Pub/Sub topic.
Step-by-Step Guide
- Install Pulumi and GCP Provider: Ensure you have Pulumi installed and the GCP provider configured.
- Create a Pub/Sub Topic: Define a Pub/Sub topic where messages will be published.
- Create an IAM Binding: Define an IAM binding to manage access control for the Pub/Sub topic.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Create a Pub/Sub Topic
const topic = new gcp.pubsub.Topic("my-topic", {
name: "my-topic",
});
// Create an IAM Binding for the Pub/Sub Topic
const topicIamBinding = new gcp.pubsub.TopicIAMBinding("my-topic-iam-binding", {
topic: topic.name,
role: "roles/pubsub.publisher", // Role to be assigned
members: [
"serviceAccount:my-service-account@example.iam.gserviceaccount.com", // Members to be assigned the role
],
});
// Export the name of the topic
export const topicName = topic.name;
Summary
In this guide, we created a Google Cloud Pub/Sub Topic and an IAM Binding using Pulumi in TypeScript. The Pub/Sub Topic allows messages to be published, and the IAM Binding manages access control by assigning roles to specified members. This setup ensures that only authorized members can publish messages to the topic.
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.