The gcp:gkehub/scopeIamPolicy:ScopeIamPolicy resource, part of the Pulumi GCP provider, manages IAM policies for GKE Hub scopes. GKE Hub scopes organize clusters and workloads within a fleet; IAM policies control who can view, modify, or manage those scopes. This guide focuses on three approaches: authoritative policy replacement (ScopeIamPolicy), role-level member management (ScopeIamBinding), and individual member grants (ScopeIamMember).
All three resources reference existing GKE Hub scopes by scopeId and project. The examples are intentionally small. Combine them with your own scope infrastructure and organizational IAM strategy.
Replace the entire IAM policy for a scope
When you need complete control over all IAM bindings for a scope, you can set the entire policy at once.
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.gkehub.ScopeIamPolicy("policy", {
project: scope.project,
scopeId: scope.scopeId,
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.gkehub.ScopeIamPolicy("policy",
project=scope["project"],
scope_id=scope["scopeId"],
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/gkehub"
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
"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 = gkehub.NewScopeIamPolicy(ctx, "policy", &gkehub.ScopeIamPolicyArgs{
Project: pulumi.Any(scope.Project),
ScopeId: pulumi.Any(scope.ScopeId),
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.GkeHub.ScopeIamPolicy("policy", new()
{
Project = scope.Project,
ScopeId = scope.ScopeId,
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.gkehub.ScopeIamPolicy;
import com.pulumi.gcp.gkehub.ScopeIamPolicyArgs;
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 ScopeIamPolicy("policy", ScopeIamPolicyArgs.builder()
.project(scope.project())
.scopeId(scope.scopeId())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:gkehub:ScopeIamPolicy
properties:
project: ${scope.project}
scopeId: ${scope.scopeId}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/viewer
members:
- user:jane@example.com
ScopeIamPolicy is authoritative: it replaces any existing policy on the scope. The policyData property accepts output from the getIAMPolicy data source, which defines bindings (role-to-members mappings). This approach gives you full control but requires managing all roles and members in one place. ScopeIamPolicy cannot be used alongside ScopeIamBinding or ScopeIamMember, as they would conflict over policy ownership.
Grant a role to multiple members at once
When multiple users or service accounts need the same role, you can bind them together while preserving other roles.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.gkehub.ScopeIamBinding("binding", {
project: scope.project,
scopeId: scope.scopeId,
role: "roles/viewer",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.gkehub.ScopeIamBinding("binding",
project=scope["project"],
scope_id=scope["scopeId"],
role="roles/viewer",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/gkehub"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := gkehub.NewScopeIamBinding(ctx, "binding", &gkehub.ScopeIamBindingArgs{
Project: pulumi.Any(scope.Project),
ScopeId: pulumi.Any(scope.ScopeId),
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.GkeHub.ScopeIamBinding("binding", new()
{
Project = scope.Project,
ScopeId = scope.ScopeId,
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.gkehub.ScopeIamBinding;
import com.pulumi.gcp.gkehub.ScopeIamBindingArgs;
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 ScopeIamBinding("binding", ScopeIamBindingArgs.builder()
.project(scope.project())
.scopeId(scope.scopeId())
.role("roles/viewer")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:gkehub:ScopeIamBinding
properties:
project: ${scope.project}
scopeId: ${scope.scopeId}
role: roles/viewer
members:
- user:jane@example.com
ScopeIamBinding is authoritative for one role: it controls the complete member list for that role but leaves other roles untouched. The members property accepts a list of identities (users, service accounts, groups). You can use multiple ScopeIamBinding resources for different roles, or combine them with ScopeIamMember resources as long as they don’t target the same role.
Add a single member to a role incrementally
When you need to grant access to one user without managing the full member list, you can add them individually.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.gkehub.ScopeIamMember("member", {
project: scope.project,
scopeId: scope.scopeId,
role: "roles/viewer",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.gkehub.ScopeIamMember("member",
project=scope["project"],
scope_id=scope["scopeId"],
role="roles/viewer",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/gkehub"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := gkehub.NewScopeIamMember(ctx, "member", &gkehub.ScopeIamMemberArgs{
Project: pulumi.Any(scope.Project),
ScopeId: pulumi.Any(scope.ScopeId),
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.GkeHub.ScopeIamMember("member", new()
{
Project = scope.Project,
ScopeId = scope.ScopeId,
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.gkehub.ScopeIamMember;
import com.pulumi.gcp.gkehub.ScopeIamMemberArgs;
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 ScopeIamMember("member", ScopeIamMemberArgs.builder()
.project(scope.project())
.scopeId(scope.scopeId())
.role("roles/viewer")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:gkehub:ScopeIamMember
properties:
project: ${scope.project}
scopeId: ${scope.scopeId}
role: roles/viewer
member: user:jane@example.com
ScopeIamMember is non-authoritative: it adds one member to a role without affecting other members. The member property accepts a single identity. This is the safest approach when multiple teams manage access independently, as it avoids accidentally removing other members’ access.
Beyond these examples
These snippets focus on specific IAM management approaches: authoritative vs non-authoritative IAM management, and policy-level, role-level, and member-level control. They’re intentionally minimal rather than full access control systems.
The examples reference pre-existing infrastructure such as GKE Hub scopes (referenced by scopeId). They focus on IAM policy configuration rather than provisioning the underlying scope resources.
To keep things focused, common IAM patterns are omitted, including:
- Conditional IAM bindings
- Custom role definitions
- Service account impersonation
- IAM policy retrieval (data source usage)
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 GKE Hub Scope IAM Policy resource reference for all available configuration options.
Let's manage GCP GKEHub Scope IAM Policies
Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.
Try Pulumi Cloud for FREEFrequently Asked Questions
Resource Selection & Conflicts
gcp.gkehub.ScopeIamPolicy cannot be used alongside gcp.gkehub.ScopeIamBinding or gcp.gkehub.ScopeIamMember because they will conflict over the IAM policy state.Choose based on your needs:
gcp.gkehub.ScopeIamPolicy- Replace the entire IAM policy (authoritative)gcp.gkehub.ScopeIamBinding- Manage all members for a specific role (authoritative per role)gcp.gkehub.ScopeIamMember- Add individual members without affecting others (non-authoritative)
Configuration & Usage
gcp.gkehub.ScopeIamPolicy with policyData from the gcp.organizations.getIAMPolicy data source, specifying project and scopeId.gcp.gkehub.ScopeIamBinding with the role property and a members array containing identities like user:jane@example.com.gcp.gkehub.ScopeIamMember with role and member properties. This preserves other members for the same role.project and scopeId are immutable and cannot be changed after the resource is created.Import & Migration
projects/{{project}}/locations/global/scopes/{{scope_id}}, {{project}}/{{scope_id}}, or just {{scope_id}}. Variables not provided in the import command are taken from the provider configuration.