Configure GCP Pub/Sub Topic IAM Bindings

The gcp:pubsub/topicIAMBinding:TopicIAMBinding resource, part of the Pulumi GCP provider, manages IAM role bindings for Pub/Sub topics, controlling which identities can publish, subscribe, or administer topics. This guide focuses on two capabilities: authoritative role binding (managing all members for one role) and non-authoritative member addition (adding one member at a time).

IAM resources reference existing Pub/Sub topics and require appropriate IAM permissions to modify access policies. The examples are intentionally small. Combine them with your own topic infrastructure and identity management strategy.

Grant a role to multiple members at once

Teams managing Pub/Sub access often need to grant the same role to multiple users, service accounts, or groups.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const binding = new gcp.pubsub.TopicIAMBinding("binding", {
    project: example.project,
    topic: example.name,
    role: "roles/viewer",
    members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp

binding = gcp.pubsub.TopicIAMBinding("binding",
    project=example["project"],
    topic=example["name"],
    role="roles/viewer",
    members=["user:jane@example.com"])
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/pubsub"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := pubsub.NewTopicIAMBinding(ctx, "binding", &pubsub.TopicIAMBindingArgs{
			Project: pulumi.Any(example.Project),
			Topic:   pulumi.Any(example.Name),
			Role:    pulumi.String("roles/viewer"),
			Members: pulumi.StringArray{
				pulumi.String("user:jane@example.com"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var binding = new Gcp.PubSub.TopicIAMBinding("binding", new()
    {
        Project = example.Project,
        Topic = example.Name,
        Role = "roles/viewer",
        Members = new[]
        {
            "user:jane@example.com",
        },
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.TopicIAMBinding;
import com.pulumi.gcp.pubsub.TopicIAMBindingArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var binding = new TopicIAMBinding("binding", TopicIAMBindingArgs.builder()
            .project(example.project())
            .topic(example.name())
            .role("roles/viewer")
            .members("user:jane@example.com")
            .build());

    }
}
resources:
  binding:
    type: gcp:pubsub:TopicIAMBinding
    properties:
      project: ${example.project}
      topic: ${example.name}
      role: roles/viewer
      members:
        - user:jane@example.com

The TopicIAMBinding resource is authoritative for the specified role: it replaces all members for that role with the list you provide. The members array accepts various identity formats including user emails, service accounts, groups, and special identifiers like allUsers. Other roles on the topic remain unchanged.

Add a single member to a role incrementally

When access needs evolve, you can add individual members without affecting existing grants.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const member = new gcp.pubsub.TopicIAMMember("member", {
    project: example.project,
    topic: example.name,
    role: "roles/viewer",
    member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp

member = gcp.pubsub.TopicIAMMember("member",
    project=example["project"],
    topic=example["name"],
    role="roles/viewer",
    member="user:jane@example.com")
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/pubsub"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := pubsub.NewTopicIAMMember(ctx, "member", &pubsub.TopicIAMMemberArgs{
			Project: pulumi.Any(example.Project),
			Topic:   pulumi.Any(example.Name),
			Role:    pulumi.String("roles/viewer"),
			Member:  pulumi.String("user:jane@example.com"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var member = new Gcp.PubSub.TopicIAMMember("member", new()
    {
        Project = example.Project,
        Topic = example.Name,
        Role = "roles/viewer",
        Member = "user:jane@example.com",
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.pubsub.TopicIAMMember;
import com.pulumi.gcp.pubsub.TopicIAMMemberArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var member = new TopicIAMMember("member", TopicIAMMemberArgs.builder()
            .project(example.project())
            .topic(example.name())
            .role("roles/viewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:pubsub:TopicIAMMember
    properties:
      project: ${example.project}
      topic: ${example.name}
      role: roles/viewer
      member: user:jane@example.com

The TopicIAMMember resource is non-authoritative: it adds one member to a role without replacing others already assigned. This lets you grant access incrementally as team members join or services need access. Multiple TopicIAMMember resources can target the same role, each adding a different identity.

Beyond these examples

These snippets focus on specific IAM binding features: role-based access control and authoritative vs non-authoritative member management. They’re intentionally minimal rather than full access control configurations.

The examples reference pre-existing infrastructure such as Pub/Sub topics and a GCP project with IAM permissions. They focus on configuring access bindings rather than provisioning topics or managing broader IAM policies.

To keep things focused, common IAM patterns are omitted, including:

  • Conditional IAM bindings (condition property)
  • Policy-level management (TopicIAMPolicy resource)
  • Custom role definitions
  • Federated identity configuration

These omissions are intentional: the goal is to illustrate how each IAM binding approach is wired, not provide drop-in access control modules. See the Pub/Sub Topic IAM Binding resource reference for all available configuration options.

Let's configure GCP Pub/Sub Topic IAM Bindings

Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.

Try Pulumi Cloud for FREE

Frequently Asked Questions

Resource Selection & Conflicts
What's the difference between TopicIAMPolicy, TopicIAMBinding, and TopicIAMMember?
TopicIAMPolicy is fully authoritative and replaces the entire IAM policy. TopicIAMBinding is authoritative for a specific role but preserves other roles. TopicIAMMember is non-authoritative and preserves other members for the same role.
Can I use TopicIAMPolicy with TopicIAMBinding or TopicIAMMember?
No, TopicIAMPolicy cannot be used alongside TopicIAMBinding or TopicIAMMember because they will conflict over the policy configuration.
Can I use TopicIAMBinding with TopicIAMMember?
Yes, but only if they grant different roles. Using both for the same role will cause conflicts.
Can I create multiple TopicIAMBinding resources for the same role?
No, only one TopicIAMBinding can be used per role. For additional members on the same role, use TopicIAMMember instead.
Configuration & Identity Formats
What member identity formats are supported?
The members property supports: allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, projectOwner/Editor/Viewer:{projectid}, and federated identities like principal://iam.googleapis.com/....
How do I specify custom roles?
Custom roles must use the full format [projects|organizations]/{parent-name}/roles/{role-name}, for example: projects/my-project/roles/my-custom-role.
Immutability & Constraints
What properties can't I change after creation?
The role, topic, and project properties are immutable and cannot be changed after the resource is created.

Using a different cloud?

Explore security guides for other cloud providers: