Manage GCP Pub/Sub Topic IAM Policies

The gcp:pubsub/topicIAMPolicy:TopicIAMPolicy resource, part of the Pulumi GCP provider, manages IAM permissions for Pub/Sub topics using three resources with different authoritativeness levels. This guide focuses on three capabilities: authoritative policy replacement (TopicIAMPolicy), role-level member management (TopicIAMBinding), and incremental member addition (TopicIAMMember).

These resources reference existing Pub/Sub topics and have strict compatibility rules. TopicIAMPolicy cannot be used with TopicIAMBinding or TopicIAMMember, as they will conflict over the policy state. TopicIAMBinding and TopicIAMMember can coexist only if they manage different roles. The examples are intentionally small. Combine them with your own topic infrastructure and identity management.

Replace the entire IAM policy for a topic

When you need complete control over topic access, TopicIAMPolicy sets the entire IAM policy at once, replacing any existing permissions.

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 policyData property accepts output from the getIAMPolicy data source, which defines bindings between roles and members. This resource is authoritative: it removes any IAM bindings not declared in the policy. Use this when you want to ensure no unexpected permissions exist.

Grant a role to multiple members at once

TopicIAMBinding assigns a single role to a list of members while preserving other roles on the topic.

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 lists all identities that should have the specified role. This resource is authoritative for the given role: it replaces all members for that role but leaves other roles untouched. Use this when you manage all members for a role together.

Add a single member to a role incrementally

TopicIAMMember grants access to one identity without affecting existing members or other roles.

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 a single identity to grant the role. This resource is non-authoritative: it adds the member without removing others who already have the same role. Use this when you want to grant access incrementally without coordinating with other team members’ IAM changes.

Beyond these examples

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

The examples reference pre-existing infrastructure such as Pub/Sub topics (by name and project). They focus on IAM binding configuration rather than topic provisioning.

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

  • Conditional IAM bindings (condition blocks)
  • Service account and group identities
  • Multiple roles in a single resource
  • IAM policy data source for read-only access

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 Topic IAM Policy resource reference for all available configuration options.

Let's manage GCP Pub/Sub Topic IAM Policies

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
Which IAM resource should I use for managing Pub/Sub topic permissions?

Choose based on your needs:

  • TopicIAMPolicy - Authoritative, replaces the entire IAM policy
  • TopicIAMBinding - Authoritative for a specific role, preserves other roles
  • TopicIAMMember - Non-authoritative, adds individual members while preserving existing ones
Can I use TopicIAMPolicy with TopicIAMBinding or TopicIAMMember?
No, TopicIAMPolicy cannot be used alongside TopicIAMBinding or TopicIAMMember because they will conflict over the policy state.
Can I use TopicIAMBinding and TopicIAMMember together?
Yes, but only if they manage different roles. Using both for the same role will cause conflicts.
What's the difference between authoritative and non-authoritative IAM resources?
Authoritative resources (TopicIAMPolicy, TopicIAMBinding) replace existing permissions, while non-authoritative (TopicIAMMember) adds permissions without removing existing ones.
Configuration & Setup
How do I generate the policyData for TopicIAMPolicy?
Use the gcp.organizations.getIAMPolicy data source with bindings, then pass its policyData output to the TopicIAMPolicy resource.
Can I change the project or topic after creating the IAM resource?
No, both project and topic are immutable and cannot be changed after creation.
What happens if I don't specify a project?
The project will be parsed from the parent resource identifier, or fall back to the provider’s default project if not specified.
Import & Migration
What formats can I use when importing topic IAM resources?

Three formats are supported:

  • projects/{{project}}/topics/{{name}}
  • {{project}}/{{name}}
  • {{name}}

For custom roles, use the full name: [projects/my-project|organizations/my-org]/roles/my-custom-role.

Using a different cloud?

Explore security guides for other cloud providers: