The gcp:bigquery/iamPolicy:IamPolicy resource, part of the Pulumi GCP provider, manages IAM policies for BigQuery tables, controlling who can read, write, or administer table data. This guide focuses on three approaches: authoritative policy replacement (IamPolicy), role-level member management (IamBinding), and incremental member grants (IamMember).
These resources reference existing BigQuery tables and datasets. They manage access control, not table creation. The examples are intentionally small. Combine them with your own table and dataset infrastructure.
Replace the entire IAM policy for a table
When you need complete control over table access, you can set the entire IAM policy at once, replacing any existing permissions.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const admin = gcp.organizations.getIAMPolicy({
bindings: [{
role: "roles/bigquery.dataOwner",
members: ["user:jane@example.com"],
}],
});
const policy = new gcp.bigquery.IamPolicy("policy", {
project: test.project,
datasetId: test.datasetId,
tableId: test.tableId,
policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp
admin = gcp.organizations.get_iam_policy(bindings=[{
"role": "roles/bigquery.dataOwner",
"members": ["user:jane@example.com"],
}])
policy = gcp.bigquery.IamPolicy("policy",
project=test["project"],
dataset_id=test["datasetId"],
table_id=test["tableId"],
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/bigquery"
"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/bigquery.dataOwner",
Members: []string{
"user:jane@example.com",
},
},
},
}, nil)
if err != nil {
return err
}
_, err = bigquery.NewIamPolicy(ctx, "policy", &bigquery.IamPolicyArgs{
Project: pulumi.Any(test.Project),
DatasetId: pulumi.Any(test.DatasetId),
TableId: pulumi.Any(test.TableId),
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/bigquery.dataOwner",
Members = new[]
{
"user:jane@example.com",
},
},
},
});
var policy = new Gcp.BigQuery.IamPolicy("policy", new()
{
Project = test.Project,
DatasetId = test.DatasetId,
TableId = test.TableId,
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.bigquery.IamPolicy;
import com.pulumi.gcp.bigquery.IamPolicyArgs;
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/bigquery.dataOwner")
.members("user:jane@example.com")
.build())
.build());
var policy = new IamPolicy("policy", IamPolicyArgs.builder()
.project(test.project())
.datasetId(test.datasetId())
.tableId(test.tableId())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:bigquery:IamPolicy
properties:
project: ${test.project}
datasetId: ${test.datasetId}
tableId: ${test.tableId}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/bigquery.dataOwner
members:
- user:jane@example.com
The IamPolicy resource is authoritative: it replaces the entire policy. The policyData comes from the getIAMPolicy data source, which defines bindings (role-to-members mappings). This approach gives you complete control but cannot coexist with IamBinding or IamMember resources on the same table.
Grant a role to multiple members at once
Teams often grant the same role to several users without affecting other roles on the table.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.bigquery.IamBinding("binding", {
project: test.project,
datasetId: test.datasetId,
tableId: test.tableId,
role: "roles/bigquery.dataOwner",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.bigquery.IamBinding("binding",
project=test["project"],
dataset_id=test["datasetId"],
table_id=test["tableId"],
role="roles/bigquery.dataOwner",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/bigquery"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := bigquery.NewIamBinding(ctx, "binding", &bigquery.IamBindingArgs{
Project: pulumi.Any(test.Project),
DatasetId: pulumi.Any(test.DatasetId),
TableId: pulumi.Any(test.TableId),
Role: pulumi.String("roles/bigquery.dataOwner"),
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.BigQuery.IamBinding("binding", new()
{
Project = test.Project,
DatasetId = test.DatasetId,
TableId = test.TableId,
Role = "roles/bigquery.dataOwner",
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.bigquery.IamBinding;
import com.pulumi.gcp.bigquery.IamBindingArgs;
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 IamBinding("binding", IamBindingArgs.builder()
.project(test.project())
.datasetId(test.datasetId())
.tableId(test.tableId())
.role("roles/bigquery.dataOwner")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:bigquery:IamBinding
properties:
project: ${test.project}
datasetId: ${test.datasetId}
tableId: ${test.tableId}
role: roles/bigquery.dataOwner
members:
- user:jane@example.com
The IamBinding resource is authoritative for a single role: it sets the complete member list for that role while preserving other roles. The members array lists all users or service accounts that should have this role. You can use IamBinding alongside IamMember resources as long as they manage different roles.
Add a single member to a role incrementally
When granting access to individual users, you often want to add them without disturbing existing members.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.bigquery.IamMember("member", {
project: test.project,
datasetId: test.datasetId,
tableId: test.tableId,
role: "roles/bigquery.dataOwner",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.bigquery.IamMember("member",
project=test["project"],
dataset_id=test["datasetId"],
table_id=test["tableId"],
role="roles/bigquery.dataOwner",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/bigquery"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := bigquery.NewIamMember(ctx, "member", &bigquery.IamMemberArgs{
Project: pulumi.Any(test.Project),
DatasetId: pulumi.Any(test.DatasetId),
TableId: pulumi.Any(test.TableId),
Role: pulumi.String("roles/bigquery.dataOwner"),
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.BigQuery.IamMember("member", new()
{
Project = test.Project,
DatasetId = test.DatasetId,
TableId = test.TableId,
Role = "roles/bigquery.dataOwner",
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.bigquery.IamMember;
import com.pulumi.gcp.bigquery.IamMemberArgs;
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 IamMember("member", IamMemberArgs.builder()
.project(test.project())
.datasetId(test.datasetId())
.tableId(test.tableId())
.role("roles/bigquery.dataOwner")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:bigquery:IamMember
properties:
project: ${test.project}
datasetId: ${test.datasetId}
tableId: ${test.tableId}
role: roles/bigquery.dataOwner
member: user:jane@example.com
The IamMember resource is non-authoritative: it adds one member to a role without affecting other members. This is useful for incremental grants where you don’t want to manage the complete member list. Multiple IamMember resources can safely target the same role.
Beyond these examples
These snippets focus on specific IAM management approaches: authoritative vs non-authoritative updates and role-based access control. They’re intentionally minimal rather than full access control systems.
The examples reference pre-existing infrastructure such as BigQuery tables and datasets. They focus on managing access rather than provisioning the underlying resources.
To keep things focused, common IAM patterns are omitted, including:
- Project-level configuration (project property)
- Conditional IAM bindings
- Service account creation and management
- Custom role definitions
These omissions are intentional: the goal is to illustrate how each IAM resource type works, not provide drop-in access control modules. See the BigQuery IamPolicy resource reference for all available configuration options.
Let's manage GCP BigQuery 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 Selection & Conflicts
gcp.bigquery.IamPolicy is authoritative and replaces the entire IAM policy. gcp.bigquery.IamBinding is authoritative for a specific role, preserving other roles in the policy. gcp.bigquery.IamMember is non-authoritative, adding a single member while preserving other members for that role.gcp.bigquery.IamPolicy cannot be used with gcp.bigquery.IamBinding or gcp.bigquery.IamMember as they will conflict over policy state. However, gcp.bigquery.IamBinding and gcp.bigquery.IamMember can be used together only if they don’t grant privileges to the same role.gcp.bigquery.IamPolicy when you need full control over the entire policy. Use gcp.bigquery.IamBinding to manage all members for a specific role. Use gcp.bigquery.IamMember to add individual members without affecting existing permissions.Configuration & Usage
gcp.organizations.getIAMPolicy data source with your desired bindings, then pass its policyData output to the policyData property of gcp.bigquery.IamPolicy.projects/{{project}}/datasets/{{dataset_id}}/tables/{{table_id}}, {{project}}/{{dataset_id}}/{{table_id}}, {{dataset_id}}/{{table_id}}, or {{table_id}}. Variables not provided in the import command are taken from the provider configuration.Properties & Constraints
datasetId, tableId, and project properties are all immutable and cannot be changed after resource creation.etag is a computed output property representing the etag of the IAM policy, useful for detecting policy changes.