Configure GCP Cloud Functions IAM Bindings

The gcp:cloudfunctionsv2/functionIamBinding:FunctionIamBinding resource, part of the Pulumi GCP provider, manages IAM role bindings for Cloud Functions (2nd gen) functions. This guide focuses on two capabilities: authoritative role binding that replaces all members for a role, and non-authoritative member addition that preserves existing members.

IAM bindings reference existing Cloud Functions and require appropriate IAM permissions. The examples are intentionally small. Combine them with your own function definitions and identity management workflows.

Note that FunctionIamBinding is authoritative for a given role, meaning it replaces the complete member list for that role. It can coexist with FunctionIamMember resources only if they manage different roles. FunctionIamPolicy cannot be used alongside either FunctionIamBinding or FunctionIamMember, as they will conflict over policy ownership.

Grant a role to multiple members at once

When managing team access, you often need to grant the same role to multiple users or service accounts simultaneously.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const binding = new gcp.cloudfunctionsv2.FunctionIamBinding("binding", {
    project: _function.project,
    location: _function.location,
    cloudFunction: _function.name,
    role: "roles/viewer",
    members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp

binding = gcp.cloudfunctionsv2.FunctionIamBinding("binding",
    project=function["project"],
    location=function["location"],
    cloud_function=function["name"],
    role="roles/viewer",
    members=["user:jane@example.com"])
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudfunctionsv2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudfunctionsv2.NewFunctionIamBinding(ctx, "binding", &cloudfunctionsv2.FunctionIamBindingArgs{
			Project:       pulumi.Any(function.Project),
			Location:      pulumi.Any(function.Location),
			CloudFunction: pulumi.Any(function.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.CloudFunctionsV2.FunctionIamBinding("binding", new()
    {
        Project = function.Project,
        Location = function.Location,
        CloudFunction = function.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.cloudfunctionsv2.FunctionIamBinding;
import com.pulumi.gcp.cloudfunctionsv2.FunctionIamBindingArgs;
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 FunctionIamBinding("binding", FunctionIamBindingArgs.builder()
            .project(function.project())
            .location(function.location())
            .cloudFunction(function.name())
            .role("roles/viewer")
            .members("user:jane@example.com")
            .build());

    }
}
resources:
  binding:
    type: gcp:cloudfunctionsv2:FunctionIamBinding
    properties:
      project: ${function.project}
      location: ${function.location}
      cloudFunction: ${function.name}
      role: roles/viewer
      members:
        - user:jane@example.com

The role property specifies which IAM role to grant (e.g., “roles/viewer” for read access). The members array lists all identities that should have this role; this resource replaces any existing members for this role on the function. The cloudFunction, project, and location properties identify which function to modify.

Add a single member to a role incrementally

When onboarding individual users, you can add access without affecting existing members who already have that role.

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const member = new gcp.cloudfunctionsv2.FunctionIamMember("member", {
    project: _function.project,
    location: _function.location,
    cloudFunction: _function.name,
    role: "roles/viewer",
    member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp

member = gcp.cloudfunctionsv2.FunctionIamMember("member",
    project=function["project"],
    location=function["location"],
    cloud_function=function["name"],
    role="roles/viewer",
    member="user:jane@example.com")
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudfunctionsv2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudfunctionsv2.NewFunctionIamMember(ctx, "member", &cloudfunctionsv2.FunctionIamMemberArgs{
			Project:       pulumi.Any(function.Project),
			Location:      pulumi.Any(function.Location),
			CloudFunction: pulumi.Any(function.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.CloudFunctionsV2.FunctionIamMember("member", new()
    {
        Project = function.Project,
        Location = function.Location,
        CloudFunction = function.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.cloudfunctionsv2.FunctionIamMember;
import com.pulumi.gcp.cloudfunctionsv2.FunctionIamMemberArgs;
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 FunctionIamMember("member", FunctionIamMemberArgs.builder()
            .project(function.project())
            .location(function.location())
            .cloudFunction(function.name())
            .role("roles/viewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:cloudfunctionsv2:FunctionIamMember
    properties:
      project: ${function.project}
      location: ${function.location}
      cloudFunction: ${function.name}
      role: roles/viewer
      member: user:jane@example.com

The member property (singular) specifies one identity to add. Unlike FunctionIamBinding, FunctionIamMember is non-authoritative: it adds this member to the role without removing others. This is useful when multiple teams manage access independently, as long as they don’t grant the same role.

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 complete access control configurations.

The examples reference pre-existing infrastructure such as Cloud Functions (2nd gen) functions and a GCP project with appropriate IAM permissions. They focus on configuring access bindings rather than provisioning the functions themselves.

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

  • Conditional IAM bindings (condition property)
  • Complete policy replacement (FunctionIamPolicy)
  • Custom role definitions
  • Federated identity configuration

These omissions are intentional: the goal is to illustrate how each binding approach is wired, not provide drop-in access control modules. See the Cloud Functions FunctionIamBinding resource reference for all available configuration options.

Let's configure GCP Cloud Functions IAM Bindings

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
Which IAM resource should I use for Cloud Functions?
Choose based on your needs: gcp.cloudfunctionsv2.FunctionIamPolicy replaces the entire IAM policy (authoritative). gcp.cloudfunctionsv2.FunctionIamBinding manages all members for a specific role (authoritative for that role, preserves other roles). gcp.cloudfunctionsv2.FunctionIamMember adds a single member to a role (non-authoritative, preserves other members).
Can I use FunctionIamPolicy with FunctionIamBinding or FunctionIamMember?
No, gcp.cloudfunctionsv2.FunctionIamPolicy cannot be used with gcp.cloudfunctionsv2.FunctionIamBinding or gcp.cloudfunctionsv2.FunctionIamMember because they will conflict over the policy configuration.
Can I use FunctionIamBinding and FunctionIamMember together?
Yes, but only if they manage different roles. gcp.cloudfunctionsv2.FunctionIamBinding and gcp.cloudfunctionsv2.FunctionIamMember conflict if they grant privileges to the same role.
Configuration & Identity Management
What member identity formats are supported?
The members property supports: allUsers, allAuthenticatedUsers, user:{emailid}, serviceAccount:{emailid}, group:{emailid}, domain:{domain}, projectOwner:projectid, projectEditor:projectid, projectViewer:projectid, and federated identities (e.g., principal://iam.googleapis.com/...).
What format do custom roles need?
Custom roles must use the format [projects|organizations]/{parent-name}/roles/{role-name} (e.g., projects/my-project/roles/my-custom-role).
Immutability & Constraints
What properties can't be changed after creation?
The cloudFunction, location, project, role, and condition properties are immutable and require resource replacement if changed.

Using a different cloud?

Explore security guides for other cloud providers: