google_bigquery_dataset

Datasets allow you to organize and control access to your tables.

To get more information about Dataset, see:

Open in Cloud Shell

Example Usage - Bigquery Dataset Basic

resource "google_bigquery_dataset" "dataset" {
  dataset_id                  = "example_dataset"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "EU"
  default_table_expiration_ms = 3600000

  labels = {
    env = "default"
  }

  access {
    role          = "OWNER"
    user_by_email = google_service_account.bqowner.email
  }

  access {
    role   = "READER"
    domain = "hashicorp.com"
  }
}

resource "google_service_account" "bqowner" {
  account_id = "bqowner"
}
## Example Usage - Bigquery Dataset Cmek
resource "google_bigquery_dataset" "dataset" {
  dataset_id                  = "example_dataset"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "US"
  default_table_expiration_ms = 3600000

  default_encryption_configuration {
    kms_key_name = google_kms_crypto_key.crypto_key.id
  }
}

resource "google_kms_crypto_key" "crypto_key" {
  name     = "example-key"
  key_ring = google_kms_key_ring.key_ring.id
}

resource "google_kms_key_ring" "key_ring" {
  name     = "example-keyring"
  location = "us"
}
Open in Cloud Shell

Example Usage - Bigquery Dataset Authorized Dataset

resource "google_bigquery_dataset" "public" {
  dataset_id                  = "public"
  friendly_name               = "test"
  description                 = "This dataset is public"
  location                    = "EU"
  default_table_expiration_ms = 3600000

  labels = {
    env = "default"
  }

  access {
    role          = "OWNER"
    user_by_email = google_service_account.bqowner.email
  }

  access {
    role   = "READER"
    domain = "hashicorp.com"
  }
}

resource "google_bigquery_dataset" "dataset" {
  dataset_id                  = "private"
  friendly_name               = "test"
  description                 = "This dataset is private"
  location                    = "EU"
  default_table_expiration_ms = 3600000

  labels = {
    env = "default"
  }

  access {
    role          = "OWNER"
    user_by_email = google_service_account.bqowner.email
  }

  access {
    role   = "READER"
    domain = "hashicorp.com"
  }

  access {
    dataset {
      dataset {
        project_id = google_bigquery_dataset.public.project
        dataset_id = google_bigquery_dataset.public.dataset_id
      }
      target_types = ["VIEWS"]
    }
  }
}

resource "google_service_account" "bqowner" {
  account_id = "bqowner"
}

Example Usage - Bigquery Dataset Authorized Routine

resource "google_bigquery_dataset" "public" {
  dataset_id  = "public_dataset"
  description = "This dataset is public"
}

resource "google_bigquery_routine" "public" {
  dataset_id      = google_bigquery_dataset.public.dataset_id
  routine_id      = "public_routine"
  routine_type    = "TABLE_VALUED_FUNCTION"
  language        = "SQL"
  definition_body = <<-EOS
    SELECT 1 + value AS value
  EOS
  arguments {
    name          = "value"
    argument_kind = "FIXED_TYPE"
    data_type     = jsonencode({ "typeKind" = "INT64" })
  }
  return_table_type = jsonencode({ "columns" = [
    { "name" = "value", "type" = { "typeKind" = "INT64" } },
  ] })
}

resource "google_bigquery_dataset" "private" {
  dataset_id  = "private_dataset"
  description = "This dataset is private"
  access {
    role          = "OWNER"
    user_by_email = "my@service-account.com"
  }
  access {
    routine {
      project_id = google_bigquery_routine.public.project
      dataset_id = google_bigquery_routine.public.dataset_id
      routine_id = google_bigquery_routine.public.routine_id
    }
  }
}

Example Usage - Bigquery Dataset External Reference Aws

resource "google_bigquery_dataset" "dataset" {
  dataset_id                  = "example_dataset"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "aws-us-east-1"

  external_dataset_reference {
    external_source = "aws-glue://arn:aws:glue:us-east-1:999999999999:database/database"
    connection      = "projects/project/locations/aws-us-east-1/connections/connection"
  }
}

Argument Reference

The following arguments are supported:


The access block supports:

The view block supports:

The dataset block supports:

The dataset block supports:

The routine block supports:

The external_dataset_reference block supports:

The default_encryption_configuration block supports:

Attributes Reference

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

Timeouts

This resource provides the following Timeouts configuration options:

Import

Dataset can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Dataset using one of the formats above. For example:

import {
  id = "projects/{{project}}/datasets/{{dataset_id}}"
  to = google_bigquery_dataset.default
}

When using the terraform import command, Dataset can be imported using one of the formats above. For example:

$ terraform import google_bigquery_dataset.default projects/{{project}}/datasets/{{dataset_id}}
$ terraform import google_bigquery_dataset.default {{project}}/{{dataset_id}}
$ terraform import google_bigquery_dataset.default {{dataset_id}}

User Project Overrides

This resource supports User Project Overrides.