Manage GCP Pub/Sub Topic IAM Permissions

The gcp:pubsub/topicIAMMember:TopicIAMMember resource, part of the Pulumi GCP provider, manages IAM permissions for Pub/Sub topics by granting roles to identities. This guide focuses on three capabilities: single-member role grants, multi-member role bindings, and full policy replacement.

IAM resources reference existing Pub/Sub topics and require a configured GCP project. The examples demonstrate three different resources (TopicIAMMember, TopicIAMBinding, TopicIAMPolicy) that serve different use cases. TopicIAMPolicy cannot be used with TopicIAMBinding or TopicIAMMember, as they will conflict over policy state. TopicIAMBinding and TopicIAMMember can coexist only if they manage different roles.

Grant a role to a single member

Most IAM configurations grant a specific role to one identity without affecting other members who already have that role.

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 member property specifies one identity using formats like user:jane@example.com, serviceAccount:app@project.iam.gserviceaccount.com, or group:team@example.com. The role property sets the permission level. This resource is non-authoritative: it adds the member to the role without removing existing members.

Grant a role to multiple members at once

When multiple identities need the same role, TopicIAMBinding manages the complete member list for that role.

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 members property takes an array of identities. This resource is authoritative for the specified role: it replaces all members for that role but preserves other roles on the topic. Use TopicIAMMember instead if you need to add members incrementally without managing the full list.

Replace the entire IAM policy

Some deployments require complete control over all IAM bindings, replacing any existing policy.

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

const admin = gcp.organizations.getIAMPolicy({
    bindings: [{
        role: "roles/viewer",
        members: ["user:jane@example.com"],
    }],
});
const policy = new gcp.pubsub.TopicIAMPolicy("policy", {
    project: example.project,
    topic: example.name,
    policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp

admin = gcp.organizations.get_iam_policy(bindings=[{
    "role": "roles/viewer",
    "members": ["user:jane@example.com"],
}])
policy = gcp.pubsub.TopicIAMPolicy("policy",
    project=example["project"],
    topic=example["name"],
    policy_data=admin.policy_data)
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
	"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 {
		admin, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
			Bindings: []organizations.GetIAMPolicyBinding{
				{
					Role: "roles/viewer",
					Members: []string{
						"user:jane@example.com",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = pubsub.NewTopicIAMPolicy(ctx, "policy", &pubsub.TopicIAMPolicyArgs{
			Project:    pulumi.Any(example.Project),
			Topic:      pulumi.Any(example.Name),
			PolicyData: pulumi.String(admin.PolicyData),
		})
		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 admin = Gcp.Organizations.GetIAMPolicy.Invoke(new()
    {
        Bindings = new[]
        {
            new Gcp.Organizations.Inputs.GetIAMPolicyBindingInputArgs
            {
                Role = "roles/viewer",
                Members = new[]
                {
                    "user:jane@example.com",
                },
            },
        },
    });

    var policy = new Gcp.PubSub.TopicIAMPolicy("policy", new()
    {
        Project = example.Project,
        Topic = example.Name,
        PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
    });

});
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.OrganizationsFunctions;
import com.pulumi.gcp.organizations.inputs.GetIAMPolicyArgs;
import com.pulumi.gcp.pubsub.TopicIAMPolicy;
import com.pulumi.gcp.pubsub.TopicIAMPolicyArgs;
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) {
        final var admin = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder()
            .bindings(GetIAMPolicyBindingArgs.builder()
                .role("roles/viewer")
                .members("user:jane@example.com")
                .build())
            .build());

        var policy = new TopicIAMPolicy("policy", TopicIAMPolicyArgs.builder()
            .project(example.project())
            .topic(example.name())
            .policyData(admin.policyData())
            .build());

    }
}
resources:
  policy:
    type: gcp:pubsub:TopicIAMPolicy
    properties:
      project: ${example.project}
      topic: ${example.name}
      policyData: ${admin.policyData}
variables:
  admin:
    fn::invoke:
      function: gcp:organizations:getIAMPolicy
      arguments:
        bindings:
          - role: roles/viewer
            members:
              - user:jane@example.com

The getIAMPolicy data source constructs a policy document from bindings. The policyData property receives the serialized policy. This resource is fully authoritative: it replaces all IAM bindings on the topic. It cannot coexist with TopicIAMBinding or TopicIAMMember resources for the same topic.

Beyond these examples

These snippets focus on specific IAM management approaches: single-member grants, multi-member role bindings, and full policy replacement. They’re intentionally minimal rather than complete access control configurations.

The examples reference pre-existing infrastructure such as Pub/Sub topics and a GCP project with configured provider. They focus on IAM binding configuration rather than topic provisioning.

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

  • Conditional IAM bindings (condition property)
  • Custom role definitions
  • Federated identity principals
  • Domain-wide delegation patterns

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

Let's manage GCP Pub/Sub Topic IAM Permissions

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
Why can't I use TopicIAMPolicy with TopicIAMBinding or TopicIAMMember?
TopicIAMPolicy is authoritative and replaces the entire IAM policy. Using it with TopicIAMBinding or TopicIAMMember causes conflicts as they fight over the policy state. Use TopicIAMPolicy alone, or use TopicIAMBinding/TopicIAMMember together.
Can I use TopicIAMBinding and TopicIAMMember together?
Yes, but only if they grant different roles. Using both for the same role causes conflicts. For example, you can use TopicIAMBinding for roles/viewer and TopicIAMMember for roles/editor, but not both for roles/viewer.
What's the difference between TopicIAMPolicy, TopicIAMBinding, and TopicIAMMember?
TopicIAMPolicy is authoritative and replaces the entire policy. TopicIAMBinding is authoritative for a specific role, replacing all members for that role while preserving other roles. TopicIAMMember is non-authoritative, adding a single member without affecting other members for the role.
IAM Configuration
How do I specify custom roles?
Custom roles must use the format [projects|organizations]/{parent-name}/roles/{role-name}. For example, projects/my-project/roles/my-custom-role or organizations/my-org/roles/my-custom-role.
What member identity formats are supported?
Supported formats include allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, projectOwner:{projectid}, projectEditor:{projectid}, projectViewer:{projectid}, and federated identities like principal://iam.googleapis.com/....
Resource Behavior
What properties can't I change after creating a TopicIAMMember?
All properties are immutable: member, role, topic, project, and condition. To change any of these, you must destroy and recreate the resource.

Using a different cloud?

Explore security guides for other cloud providers: