The gcp:compute/snapshotIamBinding:SnapshotIamBinding resource, part of the Pulumi GCP provider, manages IAM role bindings for Compute Engine snapshots. This guide focuses on two capabilities: authoritative role binding (which replaces all members for a role) and non-authoritative member addition (which preserves existing members).
IAM bindings reference existing snapshots and require appropriate IAM permissions in the GCP project. The examples are intentionally small. Combine them with your own snapshot resources and identity management.
Grant a role to multiple members
When managing snapshot access, you often need to grant the same role to multiple users or service accounts. SnapshotIamBinding manages all members for a specific role as a single unit.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.compute.SnapshotIamBinding("binding", {
project: snapshot.project,
name: snapshot.name,
role: "roles/viewer",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.compute.SnapshotIamBinding("binding",
project=snapshot["project"],
name=snapshot["name"],
role="roles/viewer",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := compute.NewSnapshotIamBinding(ctx, "binding", &compute.SnapshotIamBindingArgs{
Project: pulumi.Any(snapshot.Project),
Name: pulumi.Any(snapshot.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.Compute.SnapshotIamBinding("binding", new()
{
Project = snapshot.Project,
Name = snapshot.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.compute.SnapshotIamBinding;
import com.pulumi.gcp.compute.SnapshotIamBindingArgs;
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 SnapshotIamBinding("binding", SnapshotIamBindingArgs.builder()
.project(snapshot.project())
.name(snapshot.name())
.role("roles/viewer")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:compute:SnapshotIamBinding
properties:
project: ${snapshot.project}
name: ${snapshot.name}
role: roles/viewer
members:
- user:jane@example.com
The role property specifies which permission set to grant (e.g., “roles/viewer”). The members array lists all identities that receive this role. This resource is authoritative for the specified role: it replaces any existing members for that role on the snapshot. The name and project properties identify which snapshot to configure.
Add a single member to a role
When you need to grant access to one additional user without affecting existing members, use SnapshotIamMember instead of SnapshotIamBinding.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.compute.SnapshotIamMember("member", {
project: snapshot.project,
name: snapshot.name,
role: "roles/viewer",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.compute.SnapshotIamMember("member",
project=snapshot["project"],
name=snapshot["name"],
role="roles/viewer",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := compute.NewSnapshotIamMember(ctx, "member", &compute.SnapshotIamMemberArgs{
Project: pulumi.Any(snapshot.Project),
Name: pulumi.Any(snapshot.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.Compute.SnapshotIamMember("member", new()
{
Project = snapshot.Project,
Name = snapshot.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.compute.SnapshotIamMember;
import com.pulumi.gcp.compute.SnapshotIamMemberArgs;
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 SnapshotIamMember("member", SnapshotIamMemberArgs.builder()
.project(snapshot.project())
.name(snapshot.name())
.role("roles/viewer")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:compute:SnapshotIamMember
properties:
project: ${snapshot.project}
name: ${snapshot.name}
role: roles/viewer
member: user:jane@example.com
The member property specifies a single identity to add. Unlike SnapshotIamBinding, this resource is non-authoritative: it adds the specified member while preserving other members already assigned to the role. This approach works well when multiple teams manage access independently, as each can add members without overwriting others’ changes.
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 Compute Engine snapshots and a GCP project with appropriate IAM permissions. They focus on configuring IAM bindings rather than creating the underlying snapshot resources.
To keep things focused, common IAM patterns are omitted, including:
- Conditional IAM bindings (condition property)
- Policy-level management (SnapshotIamPolicy)
- Custom role definitions
These omissions are intentional: the goal is to illustrate how IAM bindings are wired, not provide drop-in access control modules. See the SnapshotIamBinding resource reference for all available configuration options.
Let's configure GCP Compute Snapshot IAM Bindings
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.compute.SnapshotIamPolicy is authoritative and replaces the entire IAM policy. gcp.compute.SnapshotIamBinding is authoritative for a specific role, preserving other roles in the policy. gcp.compute.SnapshotIamMember is non-authoritative, adding individual members to a role without affecting existing members.gcp.compute.SnapshotIamPolicy cannot be used with gcp.compute.SnapshotIamBinding or gcp.compute.SnapshotIamMember, as they will conflict. However, gcp.compute.SnapshotIamBinding and gcp.compute.SnapshotIamMember can be used together only if they don’t grant privileges to the same role.Configuration & Identity Formats
The members property supports multiple formats:
allUsersandallAuthenticatedUsersfor public accessuser:{email},serviceAccount:{email},group:{email}for specific identitiesdomain:{domain}for G Suite domainsprojectOwner:,projectEditor:,projectViewer:with project ID- Federated identities using
principal://format (see Principal identifiers documentation)
gcp.compute.SnapshotIamBinding with the members property as an array containing multiple identity strings (e.g., ["user:jane@example.com", "user:john@example.com"]).Custom Roles & Advanced Usage
[projects|organizations]/{parent-name}/roles/{role-name}. For example, projects/my-project/roles/my-custom-role or organizations/my-org/roles/my-custom-role.