The gcp:compute/snapshotIamPolicy:SnapshotIamPolicy resource, part of the Pulumi GCP provider, manages IAM policies for Compute Engine snapshots, controlling who can access snapshot resources. This guide focuses on three capabilities: authoritative policy replacement, role-level member binding, and incremental member grants.
GCP provides three related resources for snapshot IAM management: SnapshotIamPolicy (replaces entire policy), SnapshotIamBinding (manages one role’s members), and SnapshotIamMember (adds individual members). The examples are intentionally small. Choose the resource type that matches your update pattern.
Replace the entire IAM policy for a snapshot
When you need complete control over snapshot access, you can set 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.compute.SnapshotIamPolicy("policy", {
project: snapshot.project,
name: snapshot.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.compute.SnapshotIamPolicy("policy",
project=snapshot["project"],
name=snapshot["name"],
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"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 = compute.NewSnapshotIamPolicy(ctx, "policy", &compute.SnapshotIamPolicyArgs{
Project: pulumi.Any(snapshot.Project),
Name: pulumi.Any(snapshot.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.Compute.SnapshotIamPolicy("policy", new()
{
Project = snapshot.Project,
Name = snapshot.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.compute.SnapshotIamPolicy;
import com.pulumi.gcp.compute.SnapshotIamPolicyArgs;
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 SnapshotIamPolicy("policy", SnapshotIamPolicyArgs.builder()
.project(snapshot.project())
.name(snapshot.name())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:compute:SnapshotIamPolicy
properties:
project: ${snapshot.project}
name: ${snapshot.name}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/viewer
members:
- user:jane@example.com
The SnapshotIamPolicy resource is authoritative: it replaces the snapshot’s entire IAM policy with the policyData you provide. The getIAMPolicy data source constructs the policy document from bindings (role and member lists). This approach gives you full control but overwrites any permissions not included in your configuration. SnapshotIamPolicy cannot be used alongside SnapshotIamBinding or SnapshotIamMember, as they would conflict over the policy state.
Grant a role to multiple members at once
Teams often need to assign the same role to several users without affecting other roles already on the snapshot.
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 SnapshotIamBinding resource is authoritative for a single role: it sets the complete member list for that role while preserving other roles in the policy. The members property accepts a list of identities (users, service accounts, groups). You can use multiple SnapshotIamBinding resources for different roles, but each role can only be managed by one binding. SnapshotIamBinding can coexist with SnapshotIamMember 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 additional user without modifying the existing member list, non-authoritative member grants let you add permissions incrementally.
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 SnapshotIamMember resource is non-authoritative: it adds one member to a role without affecting other members already assigned to that role. The member property specifies a single identity. This approach is useful when multiple teams manage access independently, as each can add their own members without coordinating on a complete list. Multiple SnapshotIamMember resources can target the same role, and they can coexist with SnapshotIamBinding resources for different roles.
Beyond these examples
These snippets focus on specific IAM management patterns: authoritative vs non-authoritative updates, and policy-level, role-level, and member-level grants. They’re intentionally minimal rather than full access control configurations.
The examples reference pre-existing infrastructure such as Compute Engine snapshots (by name and project). They focus on IAM policy configuration rather than snapshot creation.
To keep things focused, common IAM patterns are omitted, including:
- Conditional IAM bindings (attribute-based access control)
- Service account impersonation and delegation
- Custom role definitions
- IAM policy retrieval (data source usage)
These omissions are intentional: the goal is to illustrate how each IAM resource type modifies snapshot permissions, not provide drop-in access control modules. See the Snapshot IAM Policy resource reference for all available configuration options.
Let's manage GCP Compute Snapshot 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
SnapshotIamPolicy cannot be used with SnapshotIamBinding or SnapshotIamMember because they will conflict over the policy. Use SnapshotIamPolicy alone for full policy control, or use SnapshotIamBinding/SnapshotIamMember without SnapshotIamPolicy.Choose based on your needs:
SnapshotIamPolicy- Authoritative. Replaces the entire IAM policy.SnapshotIamBinding- Authoritative for a specific role. Preserves other roles.SnapshotIamMember- Non-authoritative. Adds a single member to a role, preserving other members.
Configuration & Setup
gcp.organizations.getIAMPolicy data source to generate the policyData, then pass it to the SnapshotIamPolicy resource as shown in the examples.Properties & Immutability
name and project are immutable. Changing either requires recreating the resource.