Manage GCP Pub/Sub Schema IAM Permissions

The gcp:pubsub/schemaIamMember:SchemaIamMember resource, part of the Pulumi GCP provider, grants IAM permissions on Pub/Sub schemas by adding individual members to roles without affecting other permissions. This guide focuses on three approaches: adding single members, managing complete member lists per role, and replacing entire policies.

IAM resources for Pub/Sub schemas come in three variants with different authoritativeness levels. SchemaIamMember is non-authoritative (preserves other members), SchemaIamBinding is authoritative per role (replaces members for one role), and SchemaIamPolicy is fully authoritative (replaces the entire policy). SchemaIamPolicy cannot be used with the other two resources, as they will conflict. The examples are intentionally small. Combine them with your own schema definitions and organizational IAM patterns.

Grant a single user access to a schema

Most IAM configurations add individual users or service accounts to roles incrementally, preserving existing permissions.

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

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

member = gcp.pubsub.SchemaIamMember("member",
    project=example["project"],
    schema=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.NewSchemaIamMember(ctx, "member", &pubsub.SchemaIamMemberArgs{
			Project: pulumi.Any(example.Project),
			Schema:  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.SchemaIamMember("member", new()
    {
        Project = example.Project,
        Schema = 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.SchemaIamMember;
import com.pulumi.gcp.pubsub.SchemaIamMemberArgs;
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 SchemaIamMember("member", SchemaIamMemberArgs.builder()
            .project(example.project())
            .schema(example.name())
            .role("roles/viewer")
            .member("user:jane@example.com")
            .build());

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

The member property specifies one identity in a standard format (user:email, serviceAccount:email, group:email, or domain:domain). The role property sets the permission level. SchemaIamMember is non-authoritative: it adds this member without removing others who already have the role.

Grant multiple users the same role

When multiple users need identical permissions, SchemaIamBinding defines the complete member list for a single role.

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

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

binding = gcp.pubsub.SchemaIamBinding("binding",
    project=example["project"],
    schema=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.NewSchemaIamBinding(ctx, "binding", &pubsub.SchemaIamBindingArgs{
			Project: pulumi.Any(example.Project),
			Schema:  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.SchemaIamBinding("binding", new()
    {
        Project = example.Project,
        Schema = 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.SchemaIamBinding;
import com.pulumi.gcp.pubsub.SchemaIamBindingArgs;
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 SchemaIamBinding("binding", SchemaIamBindingArgs.builder()
            .project(example.project())
            .schema(example.name())
            .role("roles/viewer")
            .members("user:jane@example.com")
            .build());

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

The members property takes an array of identities. SchemaIamBinding is authoritative for the specified role: it replaces any existing members for that role while preserving other roles in the policy. Use this when you want to manage all members for a role in one place.

Replace the entire IAM policy for a schema

SchemaIamPolicy sets the complete IAM policy, replacing everything that existed before.

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.SchemaIamPolicy("policy", {
    project: example.project,
    schema: 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.SchemaIamPolicy("policy",
    project=example["project"],
    schema=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.NewSchemaIamPolicy(ctx, "policy", &pubsub.SchemaIamPolicyArgs{
			Project:    pulumi.Any(example.Project),
			Schema:     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.SchemaIamPolicy("policy", new()
    {
        Project = example.Project,
        Schema = 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.SchemaIamPolicy;
import com.pulumi.gcp.pubsub.SchemaIamPolicyArgs;
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 SchemaIamPolicy("policy", SchemaIamPolicyArgs.builder()
            .project(example.project())
            .schema(example.name())
            .policyData(admin.policyData())
            .build());

    }
}
resources:
  policy:
    type: gcp:pubsub:SchemaIamPolicy
    properties:
      project: ${example.project}
      schema: ${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 comes from getIAMPolicy, which constructs a policy document from bindings (role-to-members mappings). SchemaIamPolicy is fully authoritative: it replaces the entire policy. This approach conflicts with SchemaIamMember and SchemaIamBinding; use only one IAM resource type per schema.

Beyond these examples

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

The examples reference pre-existing infrastructure such as Pub/Sub schemas and a GCP project with appropriate permissions. They focus on granting access rather than creating the schemas themselves.

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

  • Conditional IAM bindings (condition property)
  • Custom role definitions
  • Federated identity configuration
  • Cross-project schema access

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

Let's manage GCP Pub/Sub Schema 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
What's the difference between SchemaIamPolicy, SchemaIamBinding, and SchemaIamMember?
SchemaIamPolicy is authoritative and replaces the entire IAM policy. SchemaIamBinding is authoritative for a specific role, preserving other roles. SchemaIamMember is non-authoritative, adding a single member to a role while preserving other members.
Can I use SchemaIamPolicy with SchemaIamBinding or SchemaIamMember?
No, SchemaIamPolicy cannot be used with SchemaIamBinding or SchemaIamMember, as they will conflict over the policy configuration.
Can I use SchemaIamBinding and SchemaIamMember together?
Yes, but only if they don’t grant privileges to the same role. Each role must be managed by only one resource type.
Which IAM resource should I use to grant a role to a single user?
Use SchemaIamMember to grant a role to a single member while preserving other members for that role.
Identity & Role Configuration
What identity formats are supported for the member property?
Supported formats include allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, projectOwner/Editor/Viewer:{projectid}, and federated identities like principal://iam.googleapis.com/....
What's the required format for custom roles?
Custom roles must use the format [projects|organizations]/{parent-name}/roles/{role-name}.
How do I grant a role to all authenticated users?
Set member to allAuthenticatedUsers to grant access to anyone authenticated with a Google account or service account.
Resource Management
What properties are immutable after creation?
All properties are immutable: member, role, schema, project, and condition. Changes require resource replacement.
How do I import an existing IAM member binding?
Use space-delimited identifiers: the schema resource, role, and member identity. For example: pulumi import gcp:pubsub/schemaIamMember:SchemaIamMember editor "projects/{{project}}/schemas/{{schema}} roles/viewer user:jane@example.com".

Using a different cloud?

Explore security guides for other cloud providers: