Manage GCP Service Directory IAM Bindings

The gcp:servicedirectory/serviceIamBinding:ServiceIamBinding resource, part of the Pulumi GCP provider, manages IAM role bindings for Service Directory services. It grants roles to lists of members while preserving other roles on the service. This guide focuses on two capabilities: granting roles to multiple members and adding individual members non-authoritatively.

ServiceIamBinding is authoritative for a given role, meaning it replaces all members for that role. ServiceIamMember is non-authoritative, adding one member without affecting others. ServiceIamPolicy cannot be used alongside these resources, as they conflict over policy ownership. The examples are intentionally small. Combine them with your own Service Directory infrastructure and principal identities.

Grant a role to multiple members

Teams managing Service Directory services grant IAM roles to groups of users, service accounts, or other principals.

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

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

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

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := servicedirectory.NewServiceIamBinding(ctx, "binding", &servicedirectory.ServiceIamBindingArgs{
			Name: 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.ServiceDirectory.ServiceIamBinding("binding", new()
    {
        Name = 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.servicedirectory.ServiceIamBinding;
import com.pulumi.gcp.servicedirectory.ServiceIamBindingArgs;
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 ServiceIamBinding("binding", ServiceIamBindingArgs.builder()
            .name(example.name())
            .role("roles/viewer")
            .members("user:jane@example.com")
            .build());

    }
}
resources:
  binding:
    type: gcp:servicedirectory:ServiceIamBinding
    properties:
      name: ${example.name}
      role: roles/viewer
      members:
        - user:jane@example.com

The name property references the Service Directory service. The role property specifies which IAM role to grant (predefined or custom). The members array lists all principals who should have this role; ServiceIamBinding replaces any existing members for this role, but preserves other roles on the service.

Add a single member to a role

When you need to grant access to one additional user without affecting existing members, ServiceIamMember adds a single principal non-authoritatively.

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

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

member = gcp.servicedirectory.ServiceIamMember("member",
    name=example["name"],
    role="roles/viewer",
    member="user:jane@example.com")
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := servicedirectory.NewServiceIamMember(ctx, "member", &servicedirectory.ServiceIamMemberArgs{
			Name:   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.ServiceDirectory.ServiceIamMember("member", new()
    {
        Name = 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.servicedirectory.ServiceIamMember;
import com.pulumi.gcp.servicedirectory.ServiceIamMemberArgs;
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 ServiceIamMember("member", ServiceIamMemberArgs.builder()
            .name(example.name())
            .role("roles/viewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:servicedirectory:ServiceIamMember
    properties:
      name: ${example.name}
      role: roles/viewer
      member: user:jane@example.com

The member property (singular) specifies one principal to add. Unlike ServiceIamBinding, ServiceIamMember preserves existing members for the role. You can use multiple ServiceIamMember resources for the same role, or combine ServiceIamMember with ServiceIamBinding as long as they target different roles.

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 Service Directory services (namespace and service must exist). They focus on configuring IAM bindings rather than provisioning the services themselves.

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

  • Conditional IAM bindings (condition property)
  • Custom role definitions and formatting
  • ServiceIamPolicy for full policy replacement
  • Federated identity and workload identity principals

These omissions are intentional: the goal is to illustrate how IAM bindings are wired, not provide drop-in access control modules. See the Service Directory ServiceIamBinding resource reference for all available configuration options.

Let's manage GCP Service Directory 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 ServiceIamPolicy, ServiceIamBinding, and ServiceIamMember?
ServiceIamPolicy is authoritative for the entire IAM policy and replaces any existing policy. ServiceIamBinding is authoritative for a specific role, preserving other roles. ServiceIamMember is non-authoritative and adds individual members to a role without affecting other members.
Can I use ServiceIamPolicy together with ServiceIamBinding or ServiceIamMember?
No, ServiceIamPolicy cannot be used with ServiceIamBinding or ServiceIamMember because they will conflict over the policy configuration.
Can I use ServiceIamBinding and ServiceIamMember together?
Yes, but only if they don’t grant privileges to the same role. Using both resources for the same role will cause conflicts.
Configuration & Member Identities
What member identity formats are supported?
You can use user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, allUsers, allAuthenticatedUsers, project roles (projectOwner:projectid, projectEditor:projectid, projectViewer:projectid), and federated identities (e.g., principal://iam.googleapis.com/...).
What properties are immutable after creation?
Both role and name are immutable and cannot be changed after the resource is created.
Custom Roles & Advanced Usage
How do I specify a custom role?
Custom roles must use the full path format: projects/{project-id}/roles/{role-name} or organizations/{org-id}/roles/{role-name}.
Can I use only one ServiceIamBinding per role?
Yes, only one ServiceIamBinding resource can be used per role. To add multiple members to a role, include them all in the members list of a single binding.

Using a different cloud?

Explore security guides for other cloud providers: