Configure GCP Cloud Run IAM Policies

The gcp:cloudrun/iamPolicy:IamPolicy resource, part of the Pulumi GCP provider, manages IAM permissions for Cloud Run services. Three related resources provide different levels of control: IamPolicy (authoritative for entire policy), IamBinding (authoritative for one role), and IamMember (non-authoritative for individual members). This guide focuses on three capabilities: authoritative policy replacement, role-level member management, and incremental member addition.

These resources reference existing Cloud Run services and have strict compatibility rules. IamPolicy cannot be used with IamBinding or IamMember on the same service. IamBinding and IamMember can coexist only if they manage different roles. The examples are intentionally small. Choose the resource that matches your authoritativeness 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, removing any permissions not declared in your code. Use this when you need full policy control and want to prevent drift from external changes.

Grant a role to multiple members at once

Teams often assign the same role to several users or service accounts without affecting other roles on the service.

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 IamBinding resource is authoritative for one role: it replaces all members for that role while preserving other roles. The members property accepts a list of identities (users, service accounts, groups). This approach works well when you manage all members for a specific role in one place.

Add a single member to a role incrementally

When granting access to one user, incremental addition avoids conflicts with other IAM resources managing the same service.

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 IamMember resource is non-authoritative: it adds one member to one role without affecting other members or roles. The member property accepts a single identity. This is the most granular approach and works well when multiple teams manage permissions independently or when integrating with external IAM management tools.

Beyond these examples

These snippets focus on specific IAM management patterns: authoritative vs incremental IAM management, and policy-level, role-level, and member-level control. 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 resource configuration rather than provisioning the services themselves.

To keep things focused, common IAM patterns are omitted, including:

  • Conditional IAM bindings (conditions property)
  • 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 FREE

Frequently Asked Questions

Resource Selection & Conflicts
What's the difference between IamPolicy, IamBinding, and IamMember?
gcp.cloudrun.IamPolicy is authoritative and replaces the entire IAM policy. gcp.cloudrun.IamBinding is authoritative for a specific role, updating members for that role while preserving other roles. gcp.cloudrun.IamMember is non-authoritative and adds a single member to a role without affecting other members.
Can I use these IAM resources together?
gcp.cloudrun.IamPolicy cannot be used with gcp.cloudrun.IamBinding or gcp.cloudrun.IamMember, as they will conflict over the policy. However, gcp.cloudrun.IamBinding and gcp.cloudrun.IamMember can be used together only if they don’t grant privileges to the same role.
Why am I seeing policy conflicts between my IAM resources?
Mixing gcp.cloudrun.IamPolicy with gcp.cloudrun.IamBinding or gcp.cloudrun.IamMember causes conflicts because IamPolicy is authoritative and replaces the entire policy. Similarly, using IamBinding and IamMember on the same role creates conflicts.
Configuration & Setup
How do I set up an IAM policy for my Cloud Run service?
Use gcp.organizations.getIAMPolicy to generate policy data with your desired bindings, then create an IamPolicy resource with the policyData, location, project, and service properties.
How do I add a single member to a role without affecting other members?
Use gcp.cloudrun.IamMember with the role, member, location, project, and service properties. This is non-authoritative and preserves existing members.
What properties can't be changed after creation?
The location, project, and service properties are immutable and cannot be changed after the resource is created.

Using a different cloud?

Explore iam guides for other cloud providers: