Manage GCP Cloud Build Connection IAM Policies

The gcp:cloudbuildv2/connectionIAMPolicy:ConnectionIAMPolicy resource, part of the Pulumi GCP provider, manages IAM policies for Cloud Build v2 connections, controlling who can view, use, or administer connection resources. This guide focuses on three approaches: authoritative policy replacement, role-level binding management, and individual member grants.

GCP provides three related resources for managing connection IAM: ConnectionIAMPolicy (replaces entire policy), ConnectionIAMBinding (manages all members for one role), and ConnectionIAMMember (adds one member non-authoritatively). The examples are intentionally small. Choose the resource that matches your management style and combine it with your existing connections.

Replace the entire IAM policy for a connection

When you need complete control over all IAM bindings, you can set the entire policy at once.

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

const admin = gcp.organizations.getIAMPolicy({
    bindings: [{
        role: "roles/cloudbuild.connectionViewer",
        members: ["user:jane@example.com"],
    }],
});
const policy = new gcp.cloudbuildv2.ConnectionIAMPolicy("policy", {
    project: my_connection.project,
    location: my_connection.location,
    name: my_connection.name,
    policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp

admin = gcp.organizations.get_iam_policy(bindings=[{
    "role": "roles/cloudbuild.connectionViewer",
    "members": ["user:jane@example.com"],
}])
policy = gcp.cloudbuildv2.ConnectionIAMPolicy("policy",
    project=my_connection["project"],
    location=my_connection["location"],
    name=my_connection["name"],
    policy_data=admin.policy_data)
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/cloudbuildv2"
	"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/cloudbuild.connectionViewer",
					Members: []string{
						"user:jane@example.com",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = cloudbuildv2.NewConnectionIAMPolicy(ctx, "policy", &cloudbuildv2.ConnectionIAMPolicyArgs{
			Project:    pulumi.Any(my_connection.Project),
			Location:   pulumi.Any(my_connection.Location),
			Name:       pulumi.Any(my_connection.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/cloudbuild.connectionViewer",
                Members = new[]
                {
                    "user:jane@example.com",
                },
            },
        },
    });

    var policy = new Gcp.CloudBuildV2.ConnectionIAMPolicy("policy", new()
    {
        Project = my_connection.Project,
        Location = my_connection.Location,
        Name = my_connection.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.cloudbuildv2.ConnectionIAMPolicy;
import com.pulumi.gcp.cloudbuildv2.ConnectionIAMPolicyArgs;
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/cloudbuild.connectionViewer")
                .members("user:jane@example.com")
                .build())
            .build());

        var policy = new ConnectionIAMPolicy("policy", ConnectionIAMPolicyArgs.builder()
            .project(my_connection.project())
            .location(my_connection.location())
            .name(my_connection.name())
            .policyData(admin.policyData())
            .build());

    }
}
resources:
  policy:
    type: gcp:cloudbuildv2:ConnectionIAMPolicy
    properties:
      project: ${["my-connection"].project}
      location: ${["my-connection"].location}
      name: ${["my-connection"].name}
      policyData: ${admin.policyData}
variables:
  admin:
    fn::invoke:
      function: gcp:organizations:getIAMPolicy
      arguments:
        bindings:
          - role: roles/cloudbuild.connectionViewer
            members:
              - user:jane@example.com

The ConnectionIAMPolicy resource is authoritative: it replaces any existing IAM policy on the connection. The policyData property accepts output from the getIAMPolicy data source, which defines bindings as role-member pairs. This approach gives you full control but removes any bindings not specified in your configuration. ConnectionIAMPolicy cannot be used alongside ConnectionIAMBinding or ConnectionIAMMember, as they will conflict over policy ownership.

Grant a role to multiple members at once

When multiple identities need the same role, you can bind them together in one resource.

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 a single role: it replaces all members for that role while preserving other roles on the connection. The members property accepts a list of identity strings (users, service accounts, groups). You can use multiple ConnectionIAMBinding resources for different roles, or combine them with ConnectionIAMMember resources as long as they don’t target the same role.

Add a single member to a role incrementally

When you need to grant access to one identity without affecting others, add them individually.

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 one role without replacing existing bindings. The member property accepts a single identity string. This approach works well when different teams or modules manage access independently, as multiple ConnectionIAMMember resources can safely target the same role.

Beyond these examples

These snippets focus on specific IAM management approaches: authoritative vs non-authoritative 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 Build v2 connections (identified by project, location, and name). They focus on IAM binding configuration rather than connection provisioning.

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

  • Conditional IAM bindings (condition blocks)
  • Service account impersonation
  • Custom role definitions
  • 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 Build v2 Connection IAM Policy resource reference for all available configuration options.

Let's manage GCP Cloud Build Connection 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 Conflicts & Compatibility
Why am I getting conflicts when using ConnectionIAMPolicy with other IAM resources?
ConnectionIAMPolicy cannot be used with ConnectionIAMBinding or ConnectionIAMMember because they will conflict over the policy state. Use ConnectionIAMPolicy alone for full policy control, or use ConnectionIAMBinding and ConnectionIAMMember without ConnectionIAMPolicy.
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 only one resource type to avoid conflicts.
IAM Resource Types
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, preserving other roles in the policy. ConnectionIAMMember is non-authoritative, adding a single member to a role while preserving other members for that role.
Which IAM resource should I use for my use case?
Use ConnectionIAMPolicy when you need complete control over the entire policy. Use ConnectionIAMBinding to manage all members for a specific role. Use ConnectionIAMMember to add individual members to a role without affecting other members.
Configuration & Usage
How do I set a complete IAM policy for a connection?
Use ConnectionIAMPolicy with policyData generated from the gcp.organizations.getIAMPolicy data source, along with project, location, and name to identify the connection.
How do I grant a role to multiple members at once?
Use ConnectionIAMBinding with the role property and a members list containing all member identities (e.g., ["user:jane@example.com"]).
How do I add a single member to a role?
Use ConnectionIAMMember with the role property and a single member identity (e.g., "user:jane@example.com").

Using a different cloud?

Explore security guides for other cloud providers: