The gcp:cloudrun/iamPolicy:IamPolicy resource, part of the Pulumi GCP provider, manages IAM policies for Cloud Run services, controlling who can invoke or manage the service. This guide focuses on three capabilities: authoritative policy replacement (IamPolicy), role-level member management (IamBinding), and incremental member addition (IamMember).
These resources reference existing Cloud Run services by name, location, and project. IamPolicy cannot be used with IamBinding or IamMember on the same service; they conflict over policy ownership. IamBinding and IamMember can coexist if they manage different roles. The examples are intentionally small. Combine them with your own Cloud Run services and access requirements.
Replace the entire IAM policy for a service
When you need complete control over service 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.cloudrun.IamPolicy("policy", {
location: _default.location,
project: _default.project,
service: _default.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.cloudrun.IamPolicy("policy",
location=default["location"],
project=default["project"],
service=default["name"],
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudrun"
"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 = cloudrun.NewIamPolicy(ctx, "policy", &cloudrun.IamPolicyArgs{
Location: pulumi.Any(_default.Location),
Project: pulumi.Any(_default.Project),
Service: pulumi.Any(_default.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.CloudRun.IamPolicy("policy", new()
{
Location = @default.Location,
Project = @default.Project,
Service = @default.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.cloudrun.IamPolicy;
import com.pulumi.gcp.cloudrun.IamPolicyArgs;
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 IamPolicy("policy", IamPolicyArgs.builder()
.location(default_.location())
.project(default_.project())
.service(default_.name())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:cloudrun:IamPolicy
properties:
location: ${default.location}
project: ${default.project}
service: ${default.name}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/viewer
members:
- user:jane@example.com
The policyData property accepts output from the getIAMPolicy data source, which defines bindings (role-to-members mappings). This resource is authoritative: it replaces the service’s entire IAM policy. Use this when you want to manage all permissions in one place, but be aware it overwrites any existing policy.
Grant a role to multiple members at once
Teams often grant the same role to several users or service accounts. IamBinding manages all members for a specific role while preserving other roles.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.cloudrun.IamBinding("binding", {
location: _default.location,
project: _default.project,
service: _default.name,
role: "roles/viewer",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.cloudrun.IamBinding("binding",
location=default["location"],
project=default["project"],
service=default["name"],
role="roles/viewer",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudrun"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := cloudrun.NewIamBinding(ctx, "binding", &cloudrun.IamBindingArgs{
Location: pulumi.Any(_default.Location),
Project: pulumi.Any(_default.Project),
Service: pulumi.Any(_default.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.CloudRun.IamBinding("binding", new()
{
Location = @default.Location,
Project = @default.Project,
Service = @default.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.cloudrun.IamBinding;
import com.pulumi.gcp.cloudrun.IamBindingArgs;
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 IamBinding("binding", IamBindingArgs.builder()
.location(default_.location())
.project(default_.project())
.service(default_.name())
.role("roles/viewer")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:cloudrun:IamBinding
properties:
location: ${default.location}
project: ${default.project}
service: ${default.name}
role: roles/viewer
members:
- user:jane@example.com
The role property specifies which role to manage; the members array lists all identities that should have that role. This resource is authoritative for the specified role: it replaces all existing members for that role but leaves other roles unchanged. Use this when you want to control exactly who has a specific role.
Add a single member to a role incrementally
When you need to grant access to one user without affecting other permissions, IamMember adds a single member to a role.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.cloudrun.IamMember("member", {
location: _default.location,
project: _default.project,
service: _default.name,
role: "roles/viewer",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.cloudrun.IamMember("member",
location=default["location"],
project=default["project"],
service=default["name"],
role="roles/viewer",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudrun"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := cloudrun.NewIamMember(ctx, "member", &cloudrun.IamMemberArgs{
Location: pulumi.Any(_default.Location),
Project: pulumi.Any(_default.Project),
Service: pulumi.Any(_default.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.CloudRun.IamMember("member", new()
{
Location = @default.Location,
Project = @default.Project,
Service = @default.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.cloudrun.IamMember;
import com.pulumi.gcp.cloudrun.IamMemberArgs;
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 IamMember("member", IamMemberArgs.builder()
.location(default_.location())
.project(default_.project())
.service(default_.name())
.role("roles/viewer")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:cloudrun:IamMember
properties:
location: ${default.location}
project: ${default.project}
service: ${default.name}
role: roles/viewer
member: user:jane@example.com
The member property specifies one identity to grant the role. This resource is non-authoritative: it adds the member without removing existing members for that role. Use this when you want to grant access incrementally, such as when different teams manage different users for the same role.
Beyond these examples
These snippets focus on specific IAM management approaches: authoritative policy replacement, role-level member management, and incremental member addition. They’re intentionally minimal rather than full access control configurations.
The examples reference pre-existing infrastructure such as Cloud Run services (by name, location, and project). They focus on IAM policy configuration rather than provisioning the services themselves.
To keep things focused, common IAM patterns are omitted, including:
- Conditional IAM bindings (conditions)
- Audit logging configuration (auditConfigs)
- Service account impersonation
- Public access (allUsers, allAuthenticatedUsers)
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 Cloud Run IamPolicy resource reference for all available configuration options.
Let's configure GCP Cloud Run 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 & Compatibility
gcp.cloudrun.IamPolicy cannot be used with gcp.cloudrun.IamBinding or gcp.cloudrun.IamMember because they will conflict over the policy state. Use IamPolicy alone for full control, or use IamBinding/IamMember without IamPolicy.gcp.cloudrun.IamBinding and gcp.cloudrun.IamMember will conflict if they grant privileges to the same role.Choose based on your needs:
- IamPolicy - Authoritative control over the entire IAM policy (replaces existing policy)
- IamBinding - Authoritative control over a specific role (preserves other roles)
- IamMember - Non-authoritative addition of a single member (preserves other members for the role)
Configuration & Setup
gcp.organizations.getIAMPolicy data source to generate policyData, then pass it to gcp.cloudrun.IamPolicy along with location, project, and service properties.location, project, and service properties are immutable and cannot be changed after creation. Only policyData can be updated.