The gcp:cloudbuildv2/connectionIAMPolicy:ConnectionIAMPolicy resource, part of the Pulumi GCP provider, manages IAM policies for Cloud Build v2 connections. This guide focuses on three approaches: authoritative policy replacement, role-level member binding, and individual member grants.
These resources reference existing Cloud Build v2 connections by project, location, and name. The examples are intentionally small. Combine them with your own connection resources and organizational IAM structure.
Replace the entire IAM policy for a connection
When you need complete control over connection access, you can set the entire IAM 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
ConnectionIAMPolicy is authoritative: it replaces any existing policy on the connection. The policyData comes from the getIAMPolicy data source, which defines bindings (role-to-members mappings). This approach gives you full control but requires listing all desired permissions in one place. Use this when you want to ensure no unexpected access exists.
Grant a role to multiple members at once
When multiple users need the same access level, you can bind them all to a single role together.
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
ConnectionIAMBinding is authoritative for the specified role: it replaces all members for that role but preserves other roles on the connection. The members array lists all identities that should have this role. This approach works well when you manage teams or groups that share the same permission level.
Add a single member to a role incrementally
When you need to grant access to one user without affecting others, add individual members non-authoritatively.
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
ConnectionIAMMember is non-authoritative: it adds one member to a role without affecting other members who already have that role. This approach is safest when multiple teams manage access independently, since it won’t overwrite permissions set elsewhere. Note that ConnectionIAMPolicy cannot be used alongside ConnectionIAMBinding or ConnectionIAMMember, as they will conflict over the policy state.
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 access control. They’re intentionally minimal rather than full access control systems.
The examples reference pre-existing infrastructure such as Cloud Build v2 connections (by project, location, and name). They focus on IAM policy configuration rather than provisioning the connections themselves.
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 management approach 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 FREEFrequently Asked Questions
Resource Conflicts & Compatibility
ConnectionIAMPolicy cannot be used with ConnectionIAMBinding or ConnectionIAMMember because they manage policies differently and will conflict. Choose one approach: use ConnectionIAMPolicy alone for full policy control, or use ConnectionIAMBinding/ConnectionIAMMember together.Resource Selection & Configuration
Three resource types with different levels of control:
- ConnectionIAMPolicy - Authoritative. Replaces the entire IAM policy.
- ConnectionIAMBinding - Authoritative for a specific role. Preserves other roles in the policy.
- ConnectionIAMMember - Non-authoritative. Adds a single member to a role without affecting other members.
gcp.organizations.getIAMPolicy data source to define your bindings, then pass its policyData output to the ConnectionIAMPolicy resource.