Manage GCP Cloud Build Connection IAM Bindings

The gcp:cloudbuildv2/connectionIAMBinding:ConnectionIAMBinding resource, part of the Pulumi GCP provider, manages IAM role bindings for Cloud Build v2 connections. This guide focuses on two capabilities: granting roles to multiple members and adding individual members non-authoritatively.

IAM bindings reference existing Cloud Build v2 connections and require valid GCP identities. The examples are intentionally small. Combine them with your own connection resources and identity management strategy.

Grant a role to multiple members at once

Teams managing connections often need to grant the same role to multiple users or service accounts simultaneously, such as giving a team read access.

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

const binding = new gcp.cloudbuildv2.ConnectionIAMBinding("binding", {
    project: my_connection.project,
    location: my_connection.location,
    name: my_connection.name,
    role: "roles/cloudbuild.connectionViewer",
    members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp

binding = gcp.cloudbuildv2.ConnectionIAMBinding("binding",
    project=my_connection["project"],
    location=my_connection["location"],
    name=my_connection["name"],
    role="roles/cloudbuild.connectionViewer",
    members=["user:jane@example.com"])
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudbuildv2.NewConnectionIAMBinding(ctx, "binding", &cloudbuildv2.ConnectionIAMBindingArgs{
			Project:  pulumi.Any(my_connection.Project),
			Location: pulumi.Any(my_connection.Location),
			Name:     pulumi.Any(my_connection.Name),
			Role:     pulumi.String("roles/cloudbuild.connectionViewer"),
			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.CloudBuildV2.ConnectionIAMBinding("binding", new()
    {
        Project = my_connection.Project,
        Location = my_connection.Location,
        Name = my_connection.Name,
        Role = "roles/cloudbuild.connectionViewer",
        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.cloudbuildv2.ConnectionIAMBinding;
import com.pulumi.gcp.cloudbuildv2.ConnectionIAMBindingArgs;
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 ConnectionIAMBinding("binding", ConnectionIAMBindingArgs.builder()
            .project(my_connection.project())
            .location(my_connection.location())
            .name(my_connection.name())
            .role("roles/cloudbuild.connectionViewer")
            .members("user:jane@example.com")
            .build());

    }
}
resources:
  binding:
    type: gcp:cloudbuildv2:ConnectionIAMBinding
    properties:
      project: ${["my-connection"].project}
      location: ${["my-connection"].location}
      name: ${["my-connection"].name}
      role: roles/cloudbuild.connectionViewer
      members:
        - user:jane@example.com

The ConnectionIAMBinding resource is authoritative for the specified role. The members array lists all identities that should have the role; any existing members not in this list are removed. The role property specifies which permission set to grant, and project, location, and name identify the connection. This approach works well when you manage all members for a role together.

Add a single member to a role incrementally

When onboarding individual users or service accounts, you can add them one at a time without affecting existing members.

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

const member = new gcp.cloudbuildv2.ConnectionIAMMember("member", {
    project: my_connection.project,
    location: my_connection.location,
    name: my_connection.name,
    role: "roles/cloudbuild.connectionViewer",
    member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp

member = gcp.cloudbuildv2.ConnectionIAMMember("member",
    project=my_connection["project"],
    location=my_connection["location"],
    name=my_connection["name"],
    role="roles/cloudbuild.connectionViewer",
    member="user:jane@example.com")
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudbuildv2.NewConnectionIAMMember(ctx, "member", &cloudbuildv2.ConnectionIAMMemberArgs{
			Project:  pulumi.Any(my_connection.Project),
			Location: pulumi.Any(my_connection.Location),
			Name:     pulumi.Any(my_connection.Name),
			Role:     pulumi.String("roles/cloudbuild.connectionViewer"),
			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.CloudBuildV2.ConnectionIAMMember("member", new()
    {
        Project = my_connection.Project,
        Location = my_connection.Location,
        Name = my_connection.Name,
        Role = "roles/cloudbuild.connectionViewer",
        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.cloudbuildv2.ConnectionIAMMember;
import com.pulumi.gcp.cloudbuildv2.ConnectionIAMMemberArgs;
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 ConnectionIAMMember("member", ConnectionIAMMemberArgs.builder()
            .project(my_connection.project())
            .location(my_connection.location())
            .name(my_connection.name())
            .role("roles/cloudbuild.connectionViewer")
            .member("user:jane@example.com")
            .build());

    }
}
resources:
  member:
    type: gcp:cloudbuildv2:ConnectionIAMMember
    properties:
      project: ${["my-connection"].project}
      location: ${["my-connection"].location}
      name: ${["my-connection"].name}
      role: roles/cloudbuild.connectionViewer
      member: user:jane@example.com

The ConnectionIAMMember resource is non-authoritative. It adds one member to a role without removing others. Use member (singular) instead of members (plural) to specify a single identity. This approach lets multiple ConnectionIAMMember resources coexist for the same role, each managing one identity independently. It’s useful when different teams or processes manage access for different users.

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

The examples reference pre-existing infrastructure such as Cloud Build v2 connections. They focus on configuring IAM bindings rather than provisioning the connections themselves.

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

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

These omissions are intentional: the goal is to illustrate how IAM bindings are wired, not provide drop-in access control modules. See the ConnectionIAMBinding resource reference for all available configuration options.

Let's manage GCP Cloud Build Connection 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 ConnectionIAMPolicy, ConnectionIAMBinding, and ConnectionIAMMember?
ConnectionIAMPolicy is authoritative and replaces the entire IAM policy. ConnectionIAMBinding is authoritative for a specific role but preserves other roles in the policy. ConnectionIAMMember is non-authoritative and adds a single member to a role while preserving existing members.
Can I use ConnectionIAMPolicy together with ConnectionIAMBinding or ConnectionIAMMember?
No, ConnectionIAMPolicy cannot be used with ConnectionIAMBinding or ConnectionIAMMember because they will conflict over policy management. Choose one approach: use Policy for full control, or use Binding/Member for incremental changes.
Can I use ConnectionIAMBinding and ConnectionIAMMember together?
Yes, but only if they don’t grant privileges to the same role. Each role must be managed by either Binding or Member resources, not both.
Member Configuration
What member identity formats are supported?
Supported formats include: allUsers, allAuthenticatedUsers, user:{email}, serviceAccount:{email}, group:{email}, domain:{domain}, projectOwner:projectid, projectEditor:projectid, projectViewer:projectid, and federated identities like principal://iam.googleapis.com/....
How do I grant a role to multiple members at once?
Use ConnectionIAMBinding with the members array property to grant a role to multiple identities simultaneously.
How do I add a single member to a role without affecting existing members?
Use ConnectionIAMMember with the member property (singular) to add one identity non-authoritatively, preserving other members.
Roles & Immutability
What format do custom roles require?
Custom roles must use the full format [projects|organizations]/{parent-name}/roles/{role-name}, for example projects/my-project/roles/my-custom-role.
Which properties can't be changed after creation?
The location, name, project, role, and condition properties are all immutable and cannot be modified after the resource is created.

Using a different cloud?

Explore security guides for other cloud providers: