Configure GCP Cloud Functions IAM Bindings

The gcp:cloudfunctions/functionIamBinding:FunctionIamBinding resource, part of the Pulumi GCP provider, grants IAM roles to members for Cloud Functions, controlling who can invoke or manage functions. This guide focuses on two capabilities: authoritative role assignment to multiple members and non-authoritative single-member grants.

IAM bindings reference existing Cloud Functions and assume members are already defined in your GCP organization. The examples are intentionally small. Combine them with your own function definitions and organizational identity management.

Grant a role to multiple members at once

When multiple users or service accounts need the same level of access, FunctionIamBinding grants a role to all members in a single resource.

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

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

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

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

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

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

The role property specifies which permissions to grant (e.g., “roles/viewer” for read access, “roles/cloudfunctions.invoker” for execution). The members array lists all identities that receive this role. FunctionIamBinding is authoritative for the specified role: it replaces any existing members for that role, but preserves other roles on the function.

Add a single member to a role incrementally

Teams managing access through multiple stacks or adding members without affecting existing grants use FunctionIamMember for non-authoritative updates.

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

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

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

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

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

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

The member property (singular) grants access to one identity without replacing other members who already have the same role. This is useful when different teams manage different subsets of access, or when you need to add access without knowing who else has it. FunctionIamMember resources for the same role can coexist; they accumulate rather than replace.

Beyond these examples

These snippets focus on specific IAM binding features: role-based access control and authoritative and non-authoritative member management. They’re intentionally minimal rather than full access control policies.

The examples reference pre-existing infrastructure such as Cloud Functions that need IAM policies. They focus on configuring access rather than provisioning functions or defining organizational identities.

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

  • Conditional IAM bindings (condition property)
  • Full policy replacement (FunctionIamPolicy resource)
  • Custom role definitions
  • Workload identity and federated identity configuration

These omissions are intentional: the goal is to illustrate how each IAM binding approach is wired, not provide drop-in access control modules. See the 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
What's the difference between FunctionIamPolicy, FunctionIamBinding, and FunctionIamMember?
FunctionIamPolicy is authoritative and replaces the entire IAM policy. FunctionIamBinding is authoritative for a specific role, preserving other roles. FunctionIamMember is non-authoritative, adding a single member to a role while preserving other members.
Can I use FunctionIamPolicy with FunctionIamBinding or FunctionIamMember?
No, FunctionIamPolicy cannot be used alongside FunctionIamBinding or FunctionIamMember because they will conflict over the IAM policy.
Can I use FunctionIamBinding and FunctionIamMember together?
Yes, but only if they manage different roles. Using both resources on the same role will cause conflicts.
IAM Configuration
What member identity formats are supported?
The members property supports multiple formats: allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, projectOwner:{projectid}, projectEditor:{projectid}, projectViewer:{projectid}, and federated identities like principal://iam.googleapis.com/....
What properties are immutable after creation?
The cloudFunction, project, region, role, and condition properties are all immutable and cannot be changed after the resource is created.
How do I specify a custom IAM role?
Custom roles must use the full path format: [projects|organizations]/{parent-name}/roles/{role-name}. For example, projects/my-project/roles/my-custom-role.
Usage & Examples
Which IAM resource should I use for my use case?
Use FunctionIamPolicy to manage the entire policy authoritatively. Use FunctionIamBinding to manage all members for a specific role. Use FunctionIamMember to add individual members without affecting others.
How do I grant viewer access to a Cloud Function?
Create a FunctionIamBinding with role: "roles/viewer" and members: ["user:jane@example.com"], specifying the function’s project, region, and cloudFunction name.

Using a different cloud?

Explore security guides for other cloud providers: