Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bigquery): update object table docs #494

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions bigquery/biglake/bigquery_create_object_table/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* This sample demonstrates how to create an Object Table in BigQuery.
* For more information please refer to:
* https://cloud.google.com/bigquery/docs/object-table-introduction
* https://cloud.google.com/bigquery/docs/object-tables
*/
/**
nevzheng marked this conversation as resolved.
Show resolved Hide resolved
* This Terraform example creates an object table in BigQuery.
* For more information, see
* https://cloud.google.com/bigquery/docs/object-table-introduction
* and
* https://cloud.google.com/bigquery/docs/object-tables
*/
nevzheng marked this conversation as resolved.
Show resolved Hide resolved

# [START bigquery_create_object_table]
# This queries the provider for project information.
data "google_project" "main" {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data "google_project" "main" {}
data "google_project" "default" {}


# This creates a connection in the US region named "my-connection-id".
# This connection is used to access the bucket.
resource "google_bigquery_connection" "default" {
connection_id = "my-connection-id"
location = "US"
cloud_resource {}
}

data "google_project" "project" {}

# This grants the previous connection IAM role access to the bucket.
resource "google_project_iam_member" "default" {
role = "roles/storage.objectViewer"
project = data.google_project.project.project_id
project = data.google_project.main.project_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
project = data.google_project.main.project_id
project = data.google_project.default.project_id

member = "serviceAccount:${google_bigquery_connection.default.cloud_resource[0].service_account_id}"
nevzheng marked this conversation as resolved.
Show resolved Hide resolved
}

# This defines a Google BigQuery dataset.
resource "google_bigquery_dataset" "default" {
dataset_id = "my_dataset_id"
}

# Cloud Storage bucket name must be unique
# This creates a bucket in the US region named "my-bucket" with a pseudorandom suffix.
resource "random_id" "bucket_name_suffix" {
byte_length = 8
}
Expand All @@ -50,6 +56,7 @@ resource "google_storage_bucket" "default" {
uniform_bucket_level_access = true
}

# This defines a BigQuery object table with manual metadata caching.
resource "google_bigquery_table" "default" {
deletion_protection = false
table_id = "my-table-id"
Expand All @@ -59,13 +66,11 @@ resource "google_bigquery_table" "default" {
autodetect = false
# REQUIRED for object tables.
nevzheng marked this conversation as resolved.
Show resolved Hide resolved
object_metadata = "SIMPLE"

# This defines the source for the prior object table.
source_uris = [
nevzheng marked this conversation as resolved.
Show resolved Hide resolved
"gs://${google_storage_bucket.default.name}/*",
]

# `MANUAL` for manual metadata refresh
# `AUTOMATIC` for automatic metadata refresh.
metadata_cache_mode = "MANUAL"
}

Expand All @@ -74,9 +79,8 @@ resource "google_bigquery_table" "default" {
# Interval literal: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#interval_literals
# max_staleness = "0-0 0 10:0:0"
nevzheng marked this conversation as resolved.
Show resolved Hide resolved

# Ensure the connection can access the bucket before table creation.
# Without this dependency, Terraform may try to create the table when
# the connection does not have the correct IAM Role resulting in failures.
# This ensures that the connection can access the bucket
# before Terraform creates a table.
depends_on = [
google_project_iam_member.default
]
Expand Down