Manage GCP Cloud Functions IAM Policies

The gcp:cloudfunctions/functionIamPolicy:FunctionIamPolicy resource, part of the Pulumi GCP provider, manages IAM permissions for Cloud Functions by setting complete policies, binding roles to member lists, or adding individual members. This guide focuses on three capabilities: authoritative policy replacement (FunctionIamPolicy), role-level member binding (FunctionIamBinding), and incremental member addition (FunctionIamMember).

These resources reference existing Cloud Functions by name, project, and region. The examples are intentionally small. Combine them with your own function definitions and organizational IAM structure.

Replace the entire IAM policy with FunctionIamPolicy

When you need complete control over function access, replacing the entire IAM policy ensures no unexpected permissions remain.

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.cloudfunctions.FunctionIamPolicy("policy", {
    project: _function.project,
    region: _function.region,
    cloudFunction: _function.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.cloudfunctions.FunctionIamPolicy("policy",
    project=function["project"],
    region=function["region"],
    cloud_function=function["name"],
    policy_data=admin.policy_data)
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudfunctions"
	"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 = cloudfunctions.NewFunctionIamPolicy(ctx, "policy", &cloudfunctions.FunctionIamPolicyArgs{
			Project:       pulumi.Any(function.Project),
			Region:        pulumi.Any(function.Region),
			CloudFunction: pulumi.Any(function.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.CloudFunctions.FunctionIamPolicy("policy", new()
    {
        Project = function.Project,
        Region = function.Region,
        CloudFunction = function.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.cloudfunctions.FunctionIamPolicy;
import com.pulumi.gcp.cloudfunctions.FunctionIamPolicyArgs;
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 FunctionIamPolicy("policy", FunctionIamPolicyArgs.builder()
            .project(function.project())
            .region(function.region())
            .cloudFunction(function.name())
            .policyData(admin.policyData())
            .build());

    }
}
resources:
  policy:
    type: gcp:cloudfunctions:FunctionIamPolicy
    properties:
      project: ${function.project}
      region: ${function.region}
      cloudFunction: ${function.name}
      policyData: ${admin.policyData}
variables:
  admin:
    fn::invoke:
      function: gcp:organizations:getIAMPolicy
      arguments:
        bindings:
          - role: roles/viewer
            members:
              - user:jane@example.com

FunctionIamPolicy is authoritative: it replaces all existing IAM bindings on the function. The policyData comes from getIAMPolicy, which defines roles and members. Any permissions not in policyData are removed when this resource applies. FunctionIamPolicy cannot be used alongside FunctionIamBinding or FunctionIamMember, as they will conflict over policy ownership.

Grant a role to multiple members with FunctionIamBinding

Teams often grant the same role to multiple users while preserving other role assignments.

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

FunctionIamBinding is authoritative for a single role: it replaces all members for that role but leaves other roles untouched. The members property accepts a list of identities (users, service accounts, groups). You can use multiple FunctionIamBinding resources for different roles, or combine them with FunctionIamMember resources as long as they don’t target the same role.

Add a single member to a role with FunctionIamMember

When you need to grant access to one additional user without disturbing existing permissions, non-authoritative member grants preserve other assignments.

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

FunctionIamMember is non-authoritative: it adds one member to a role without replacing existing members. Use this when you want incremental grants. The member property specifies a single identity. You can create multiple FunctionIamMember resources for the same role, and they will accumulate rather than conflict.

Beyond these examples

These snippets focus on specific IAM management approaches: authoritative policy replacement, role-level member binding, and incremental member addition. They’re intentionally minimal rather than full access control configurations.

The examples reference pre-existing infrastructure such as Cloud Functions (by name, project, and region). They focus on IAM permission assignment rather than function provisioning.

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

  • Conditional IAM bindings (condition blocks)
  • Service account impersonation
  • Multiple roles in a single resource
  • IAM policy retrieval (data source usage)

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 Functions FunctionIamPolicy resource reference for all available configuration options.

Let's manage GCP Cloud Functions 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
Why are my IAM resources conflicting with each other?
FunctionIamPolicy cannot be used with FunctionIamBinding or FunctionIamMember because they will fight over the policy. Choose one approach: use FunctionIamPolicy alone (authoritative), or use FunctionIamBinding/FunctionIamMember together.
Can I use FunctionIamBinding and FunctionIamMember together?
Yes, but only if they don’t grant privileges to the same role. If both resources target the same role, they will conflict.
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 and adds a single member without affecting other members for that role.
Configuration & Setup
How do I generate the policyData for FunctionIamPolicy?
Use the gcp.organizations.getIAMPolicy data source to generate policy data, then pass it to the policyData property.
What happens if I don't specify project or region?
Both project and region default to the provider configuration if not specified. They can also be parsed from the parent resource identifier.
Properties & Immutability
What properties can't I change after creation?
The cloudFunction, project, and region properties are immutable. Changing them requires recreating the resource.

Using a different cloud?

Explore security guides for other cloud providers: