The gcp:compute/subnetworkIAMPolicy:SubnetworkIAMPolicy resource, part of the Pulumi GCP provider, manages IAM permissions for VPC subnetworks, controlling which identities can use the subnetwork for VM instances and other resources. This guide focuses on four capabilities: authoritative policy replacement (SubnetworkIAMPolicy), role-level member management (SubnetworkIAMBinding), individual member grants (SubnetworkIAMMember), and time-based access with IAM Conditions.
These resources reference existing subnetworks and require project/region context. The examples are intentionally small. Combine them with your own subnetwork infrastructure and understand the conflict rules: SubnetworkIAMPolicy cannot coexist with SubnetworkIAMBinding or SubnetworkIAMMember, as they will conflict over policy state.
Replace the entire IAM policy for a subnetwork
Teams managing network access centrally often define the complete IAM policy for a subnetwork, replacing any existing permissions with a known configuration.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const admin = gcp.organizations.getIAMPolicy({
bindings: [{
role: "roles/compute.networkUser",
members: ["user:jane@example.com"],
}],
});
const policy = new gcp.compute.SubnetworkIAMPolicy("policy", {
project: network_with_private_secondary_ip_ranges.project,
region: network_with_private_secondary_ip_ranges.region,
subnetwork: network_with_private_secondary_ip_ranges.name,
policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp
admin = gcp.organizations.get_iam_policy(bindings=[{
"role": "roles/compute.networkUser",
"members": ["user:jane@example.com"],
}])
policy = gcp.compute.SubnetworkIAMPolicy("policy",
project=network_with_private_secondary_ip_ranges["project"],
region=network_with_private_secondary_ip_ranges["region"],
subnetwork=network_with_private_secondary_ip_ranges["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/compute.networkUser",
Members: []string{
"user:jane@example.com",
},
},
},
}, nil)
if err != nil {
return err
}
_, err = compute.NewSubnetworkIAMPolicy(ctx, "policy", &compute.SubnetworkIAMPolicyArgs{
Project: pulumi.Any(network_with_private_secondary_ip_ranges.Project),
Region: pulumi.Any(network_with_private_secondary_ip_ranges.Region),
Subnetwork: pulumi.Any(network_with_private_secondary_ip_ranges.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/compute.networkUser",
Members = new[]
{
"user:jane@example.com",
},
},
},
});
var policy = new Gcp.Compute.SubnetworkIAMPolicy("policy", new()
{
Project = network_with_private_secondary_ip_ranges.Project,
Region = network_with_private_secondary_ip_ranges.Region,
Subnetwork = network_with_private_secondary_ip_ranges.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.SubnetworkIAMPolicy;
import com.pulumi.gcp.compute.SubnetworkIAMPolicyArgs;
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/compute.networkUser")
.members("user:jane@example.com")
.build())
.build());
var policy = new SubnetworkIAMPolicy("policy", SubnetworkIAMPolicyArgs.builder()
.project(network_with_private_secondary_ip_ranges.project())
.region(network_with_private_secondary_ip_ranges.region())
.subnetwork(network_with_private_secondary_ip_ranges.name())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:compute:SubnetworkIAMPolicy
properties:
project: ${["network-with-private-secondary-ip-ranges"].project}
region: ${["network-with-private-secondary-ip-ranges"].region}
subnetwork: ${["network-with-private-secondary-ip-ranges"].name}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/compute.networkUser
members:
- user:jane@example.com
SubnetworkIAMPolicy is authoritative: it replaces the entire IAM policy for the subnetwork. The policyData comes from getIAMPolicy, which defines bindings (role-to-members mappings). This approach gives you complete control but requires managing all roles and members in one place.
Apply time-based access with IAM Conditions
Organizations implementing temporary access use IAM Conditions to automatically expire permissions at a specific time.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const admin = gcp.organizations.getIAMPolicy({
bindings: [{
role: "roles/compute.networkUser",
members: ["user:jane@example.com"],
condition: {
title: "expires_after_2019_12_31",
description: "Expiring at midnight of 2019-12-31",
expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
}],
});
const policy = new gcp.compute.SubnetworkIAMPolicy("policy", {
project: network_with_private_secondary_ip_ranges.project,
region: network_with_private_secondary_ip_ranges.region,
subnetwork: network_with_private_secondary_ip_ranges.name,
policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp
admin = gcp.organizations.get_iam_policy(bindings=[{
"role": "roles/compute.networkUser",
"members": ["user:jane@example.com"],
"condition": {
"title": "expires_after_2019_12_31",
"description": "Expiring at midnight of 2019-12-31",
"expression": "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
}])
policy = gcp.compute.SubnetworkIAMPolicy("policy",
project=network_with_private_secondary_ip_ranges["project"],
region=network_with_private_secondary_ip_ranges["region"],
subnetwork=network_with_private_secondary_ip_ranges["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/compute.networkUser",
Members: []string{
"user:jane@example.com",
},
Condition: {
Title: "expires_after_2019_12_31",
Description: pulumi.StringRef("Expiring at midnight of 2019-12-31"),
Expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
},
},
}, nil)
if err != nil {
return err
}
_, err = compute.NewSubnetworkIAMPolicy(ctx, "policy", &compute.SubnetworkIAMPolicyArgs{
Project: pulumi.Any(network_with_private_secondary_ip_ranges.Project),
Region: pulumi.Any(network_with_private_secondary_ip_ranges.Region),
Subnetwork: pulumi.Any(network_with_private_secondary_ip_ranges.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/compute.networkUser",
Members = new[]
{
"user:jane@example.com",
},
Condition = new Gcp.Organizations.Inputs.GetIAMPolicyBindingConditionInputArgs
{
Title = "expires_after_2019_12_31",
Description = "Expiring at midnight of 2019-12-31",
Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
},
},
},
});
var policy = new Gcp.Compute.SubnetworkIAMPolicy("policy", new()
{
Project = network_with_private_secondary_ip_ranges.Project,
Region = network_with_private_secondary_ip_ranges.Region,
Subnetwork = network_with_private_secondary_ip_ranges.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.SubnetworkIAMPolicy;
import com.pulumi.gcp.compute.SubnetworkIAMPolicyArgs;
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/compute.networkUser")
.members("user:jane@example.com")
.condition(GetIAMPolicyBindingConditionArgs.builder()
.title("expires_after_2019_12_31")
.description("Expiring at midnight of 2019-12-31")
.expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
.build())
.build())
.build());
var policy = new SubnetworkIAMPolicy("policy", SubnetworkIAMPolicyArgs.builder()
.project(network_with_private_secondary_ip_ranges.project())
.region(network_with_private_secondary_ip_ranges.region())
.subnetwork(network_with_private_secondary_ip_ranges.name())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:compute:SubnetworkIAMPolicy
properties:
project: ${["network-with-private-secondary-ip-ranges"].project}
region: ${["network-with-private-secondary-ip-ranges"].region}
subnetwork: ${["network-with-private-secondary-ip-ranges"].name}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/compute.networkUser
members:
- user:jane@example.com
condition:
title: expires_after_2019_12_31
description: Expiring at midnight of 2019-12-31
expression: request.time < timestamp("2020-01-01T00:00:00Z")
The condition block adds temporal logic to IAM bindings. The expression uses Common Expression Language (CEL) to compare request.time against a timestamp. When the condition evaluates to false, the binding no longer grants access. This works with SubnetworkIAMPolicy, SubnetworkIAMBinding, and SubnetworkIAMMember.
Grant a role to multiple members at once
When multiple users or service accounts need the same role, SubnetworkIAMBinding manages the complete member list for that role while preserving other roles.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.compute.SubnetworkIAMBinding("binding", {
project: network_with_private_secondary_ip_ranges.project,
region: network_with_private_secondary_ip_ranges.region,
subnetwork: network_with_private_secondary_ip_ranges.name,
role: "roles/compute.networkUser",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.compute.SubnetworkIAMBinding("binding",
project=network_with_private_secondary_ip_ranges["project"],
region=network_with_private_secondary_ip_ranges["region"],
subnetwork=network_with_private_secondary_ip_ranges["name"],
role="roles/compute.networkUser",
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.NewSubnetworkIAMBinding(ctx, "binding", &compute.SubnetworkIAMBindingArgs{
Project: pulumi.Any(network_with_private_secondary_ip_ranges.Project),
Region: pulumi.Any(network_with_private_secondary_ip_ranges.Region),
Subnetwork: pulumi.Any(network_with_private_secondary_ip_ranges.Name),
Role: pulumi.String("roles/compute.networkUser"),
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.SubnetworkIAMBinding("binding", new()
{
Project = network_with_private_secondary_ip_ranges.Project,
Region = network_with_private_secondary_ip_ranges.Region,
Subnetwork = network_with_private_secondary_ip_ranges.Name,
Role = "roles/compute.networkUser",
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.SubnetworkIAMBinding;
import com.pulumi.gcp.compute.SubnetworkIAMBindingArgs;
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 SubnetworkIAMBinding("binding", SubnetworkIAMBindingArgs.builder()
.project(network_with_private_secondary_ip_ranges.project())
.region(network_with_private_secondary_ip_ranges.region())
.subnetwork(network_with_private_secondary_ip_ranges.name())
.role("roles/compute.networkUser")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:compute:SubnetworkIAMBinding
properties:
project: ${["network-with-private-secondary-ip-ranges"].project}
region: ${["network-with-private-secondary-ip-ranges"].region}
subnetwork: ${["network-with-private-secondary-ip-ranges"].name}
role: roles/compute.networkUser
members:
- user:jane@example.com
SubnetworkIAMBinding is authoritative for a single role: it sets the complete member list for roles/compute.networkUser but leaves other roles untouched. The members array accepts user, serviceAccount, group, and domain identities. This resource can coexist with SubnetworkIAMMember as long as they don’t manage the same role.
Add a single member without affecting others
Applications that grant access incrementally use SubnetworkIAMMember to add individual permissions without managing the complete member list.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.compute.SubnetworkIAMMember("member", {
project: network_with_private_secondary_ip_ranges.project,
region: network_with_private_secondary_ip_ranges.region,
subnetwork: network_with_private_secondary_ip_ranges.name,
role: "roles/compute.networkUser",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.compute.SubnetworkIAMMember("member",
project=network_with_private_secondary_ip_ranges["project"],
region=network_with_private_secondary_ip_ranges["region"],
subnetwork=network_with_private_secondary_ip_ranges["name"],
role="roles/compute.networkUser",
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.NewSubnetworkIAMMember(ctx, "member", &compute.SubnetworkIAMMemberArgs{
Project: pulumi.Any(network_with_private_secondary_ip_ranges.Project),
Region: pulumi.Any(network_with_private_secondary_ip_ranges.Region),
Subnetwork: pulumi.Any(network_with_private_secondary_ip_ranges.Name),
Role: pulumi.String("roles/compute.networkUser"),
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.SubnetworkIAMMember("member", new()
{
Project = network_with_private_secondary_ip_ranges.Project,
Region = network_with_private_secondary_ip_ranges.Region,
Subnetwork = network_with_private_secondary_ip_ranges.Name,
Role = "roles/compute.networkUser",
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.SubnetworkIAMMember;
import com.pulumi.gcp.compute.SubnetworkIAMMemberArgs;
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 SubnetworkIAMMember("member", SubnetworkIAMMemberArgs.builder()
.project(network_with_private_secondary_ip_ranges.project())
.region(network_with_private_secondary_ip_ranges.region())
.subnetwork(network_with_private_secondary_ip_ranges.name())
.role("roles/compute.networkUser")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:compute:SubnetworkIAMMember
properties:
project: ${["network-with-private-secondary-ip-ranges"].project}
region: ${["network-with-private-secondary-ip-ranges"].region}
subnetwork: ${["network-with-private-secondary-ip-ranges"].name}
role: roles/compute.networkUser
member: user:jane@example.com
SubnetworkIAMMember is non-authoritative: it adds one member to one role without affecting other members for that role. Use this when you need to grant access incrementally or when multiple systems manage permissions for the same subnetwork. The member property takes a single identity string.
Beyond these examples
These snippets focus on specific IAM management features: authoritative vs non-authoritative IAM management, IAM Conditions for time-based access, and role and member binding patterns. They’re intentionally minimal rather than full access control systems.
The examples reference pre-existing infrastructure such as VPC subnetworks (referenced but not created). They focus on configuring IAM permissions rather than provisioning the underlying network resources.
To keep things focused, common IAM patterns are omitted, including:
- Resource conflicts (SubnetworkIAMPolicy cannot coexist with Binding/Member)
- Combining Binding and Member resources safely
- Custom role references (require full path format)
- IAM Conditions limitations and known issues
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 Subnetwork IAM Policy resource reference for all available configuration options.
Let's manage GCP Subnetwork 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
SubnetworkIAMPolicy is authoritative and replaces the entire IAM policy. SubnetworkIAMBinding is authoritative for a specific role, preserving other roles in the policy. SubnetworkIAMMember is non-authoritative, adding a single member to a role while preserving other members for that role.SubnetworkIAMPolicy cannot be used with SubnetworkIAMBinding or SubnetworkIAMMember as they will conflict. However, SubnetworkIAMBinding and SubnetworkIAMMember can be used together if they don’t grant privileges to the same role.SubnetworkIAMPolicy with SubnetworkIAMBinding or SubnetworkIAMMember, or using SubnetworkIAMBinding and SubnetworkIAMMember for the same role. Choose one approach per role to avoid conflicts.IAM Conditions & Time-Based Access
condition block with title, description, and expression fields. For example, set expression to request.time < timestamp("2020-01-01T00:00:00Z") to expire access at midnight on January 1, 2020.Configuration & Requirements
policyData field must be generated by the gcp.organizations.getIAMPolicy data source, which defines the bindings, roles, and members for your policy.subnetwork, project, and region fields are all immutable and cannot be changed after the resource is created.