1. Answers
  2. Sharing BigQuery datasets across different GCP projects

How do I share BigQuery datasets across different GCP projects?

In this guide, we will share a BigQuery dataset across different Google Cloud Platform (GCP) projects using Pulumi. This involves creating a BigQuery dataset in one project and granting access to users or services in another project.

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

// Define the source project where the BigQuery dataset will be created
const sourceProject = new gcp.organizations.Project("sourceProject", {
    projectId: "source-project-id",
    name: "Source Project",
    orgId: "your-org-id",
});

// Define the target project which will access the BigQuery dataset
const targetProject = new gcp.organizations.Project("targetProject", {
    projectId: "target-project-id",
    name: "Target Project",
    orgId: "your-org-id",
});

// Create a BigQuery dataset in the source project
const dataset = new gcp.bigquery.Dataset("dataset", {
    project: sourceProject.projectId,
    datasetId: "shared_dataset",
    location: "US",
    description: "A dataset shared across projects",
});

// Grant access to the target project
const datasetAccess = new gcp.bigquery.DatasetAccess("datasetAccess", {
    datasetId: dataset.datasetId,
    project: dataset.project,
    role: "READER",
    userByEmail: "target-user@example.com", // Replace with the user or service account email in the target project
});

Key Points:

  • Source Project: The project where the BigQuery dataset is created.
  • Target Project: The project that will be granted access to the dataset.
  • Dataset: The BigQuery dataset being shared.
  • Dataset Access: The access control configuration to allow the target project to access the dataset.

Summary:

In this guide, we created a BigQuery dataset in a source GCP project and granted read access to a user or service account in a target GCP project using Pulumi. This enables cross-project sharing of BigQuery datasets.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up