Skip to content

IAM policy for BigQuery dataset

Three different resources help you manage your IAM policy for BigQuery dataset. Each of these resources serves a different use case:

  • googleBigqueryDatasetIamPolicy: Authoritative. Sets the IAM policy for the dataset and replaces any existing policy already attached.
  • googleBigqueryDatasetIamBinding: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the dataset are preserved.
  • googleBigqueryDatasetIamMember: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the dataset are preserved.

These resources are intended to convert the permissions system for BigQuery datasets to the standard IAM interface. For advanced usages, including creating authorized views, please use either googleBigqueryDatasetAccess or the access field on googleBigqueryDataset.

\~> Note: These resources cannot be used with googleBigqueryDatasetAccess resources or the access field on googleBigqueryDataset or they will fight over what the policy should be.

\~> Note: Using any of these resources will remove any authorized view permissions from the dataset. To assign and preserve authorized view permissions use the googleBigqueryDatasetAccess instead.

\~> Note: Legacy BigQuery roles owner writer and reader cannot be used with any of these IAM resources. Instead use the full role form of: roles/bigqueryDataOwner roles/bigqueryDataEditor and roles/bigqueryDataViewer.

\~> Note: googleBigqueryDatasetIamPolicy cannot be used in conjunction with googleBigqueryDatasetIamBinding and googleBigqueryDatasetIamMember or they will fight over what your policy should be.

\~> Note: googleBigqueryDatasetIamBinding resources can be used in conjunction with googleBigqueryDatasetIamMember resources only if they do not grant privilege to the same role.

googleBigqueryDatasetIamPolicy

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleBigqueryDatasetDataset = new google.bigqueryDataset.BigqueryDataset(
  this,
  "dataset",
  {
    dataset_id: "example_dataset",
  }
);
const dataGoogleIamPolicyOwner =
  new google.dataGoogleIamPolicy.DataGoogleIamPolicy(this, "owner", {
    binding: [
      {
        members: ["user:jane@example.com"],
        role: "roles/bigquery.dataOwner",
      },
    ],
  });
const googleBigqueryDatasetIamPolicyDataset =
  new google.bigqueryDatasetIamPolicy.BigqueryDatasetIamPolicy(
    this,
    "dataset_2",
    {
      dataset_id: googleBigqueryDatasetDataset.datasetId,
      policy_data: dataGoogleIamPolicyOwner.policyData,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleBigqueryDatasetIamPolicyDataset.overrideLogicalId("dataset");

googleBigqueryDatasetIamBinding

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleBigqueryDatasetDataset = new google.bigqueryDataset.BigqueryDataset(
  this,
  "dataset",
  {
    dataset_id: "example_dataset",
  }
);
new google.bigqueryDatasetIamBinding.BigqueryDatasetIamBinding(this, "reader", {
  dataset_id: googleBigqueryDatasetDataset.datasetId,
  members: ["user:jane@example.com"],
  role: "roles/bigquery.dataViewer",
});

googleBigqueryDatasetIamMember

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleBigqueryDatasetDataset = new google.bigqueryDataset.BigqueryDataset(
  this,
  "dataset",
  {
    dataset_id: "example_dataset",
  }
);
new google.bigqueryDatasetIamMember.BigqueryDatasetIamMember(this, "editor", {
  dataset_id: googleBigqueryDatasetDataset.datasetId,
  member: "user:jane@example.com",
  role: "roles/bigquery.dataEditor",
});

Argument Reference

The following arguments are supported:

  • datasetId - (Required) The dataset ID.

  • member/members - (Required) Identities that will be granted the privilege in role. Each entry can have one of the following values:

    • allUsers: A special identifier that represents anyone who is on the internet; with or without a Google account.
    • allAuthenticatedUsers: A special identifier that represents anyone who is authenticated with a Google account or a service account.
    • user:{emailid}: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com.
    • serviceAccount:{emailid}: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
    • group:{emailid}: An email address that represents a Google group. For example, admins@example.com.
    • domain:{domain}: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
  • role - (Required) The role that should be applied. Only one googleBigqueryDatasetIamBinding can be used per role. Note that custom roles must be of the format [projects|organizations]/{parentName}/roles/{roleName}.

  • policyData - (Required only by googleBigqueryDatasetIamPolicy) The policy data generated by a googleIamPolicy data source.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • etag - (Computed) The etag of the dataset's IAM policy.

Import

IAM member imports use space-delimited identifiers; the resource in question, the role, and the account. This member resource can be imported using the datasetId, role, and account e.g.

$ terraform import google_bigquery_dataset_iam_member.dataset_iam "projects/your-project-id/datasets/dataset-id roles/viewer user:foo@example.com"

IAM binding imports use space-delimited identifiers; the resource in question and the role. This binding resource can be imported using the datasetId and role, e.g.

$ terraform import google_bigquery_dataset_iam_binding.dataset_iam "projects/your-project-id/datasets/dataset-id roles/viewer"

IAM policy imports use the identifier of the resource in question. This policy resource can be imported using the datasetId, role, and account e.g.

$ terraform import google_bigquery_dataset_iam_policy.dataset_iam projects/your-project-id/datasets/dataset-id

-> Custom Roles: If you're importing a IAM resource with a custom role, make sure to use the full name of the custom role, e.g. [projects/myProject|organizations/myOrg]/roles/myCustomRole.