From 429f66dcfcceda54f443436bcd32e6bdfd77edaf Mon Sep 17 00:00:00 2001 From: pratikmore0290 Date: Thu, 29 Aug 2024 20:13:52 +0000 Subject: [PATCH 1/4] feat(bigquery): Add example for creating a dataset with tag attached --- .../main.tf | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 bigquery/bigquery_create_dataset_attach_tag/main.tf diff --git a/bigquery/bigquery_create_dataset_attach_tag/main.tf b/bigquery/bigquery_create_dataset_attach_tag/main.tf new file mode 100644 index 000000000..aaa1f7b12 --- /dev/null +++ b/bigquery/bigquery_create_dataset_attach_tag/main.tf @@ -0,0 +1,56 @@ +/** +* Copyright 2024 Google LLC +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +# [START bigquery_create_dataset_attach_tag] + +data "google_project" "default" {} + +resource "google_tags_tag_key" "env_tag_key" { + parent = "projects/${data.google_project.default.project_id}" + short_name = "env2" +} + +resource "google_tags_tag_key" "department_tag_key" { + parent = "projects/${data.google_project.default.project_id}" + short_name = "department2" +} + +resource "google_tags_tag_value" "env_tag_value" { + parent = "tagKeys/${google_tags_tag_key.env_tag_key.name}" + short_name = "prod" +} + +resource "google_tags_tag_value" "department_tag_value" { + parent = "tagKeys/${google_tags_tag_key.department_tag_key.name}" + short_name = "sales" +} + +resource "google_bigquery_dataset" "default" { + dataset_id = "my_dataset" + default_partition_expiration_ms = 2592000000 # 30 days + default_table_expiration_ms = 31536000000 # 365 days + description = "dataset description" + location = "US" + max_time_travel_hours = 96 # 4 days + + # Create a dataset with resource_tags + resource_tags = { + "${google_tags_tag_key.env_tag_key.namespaced_name}" : "${google_tags_tag_value.env_tag_value.short_name}", + "${google_tags_tag_key.department_tag_key.namespaced_name}" : "${google_tags_tag_value.department_tag_value.short_name}" + } +} +# [END bigquery_create_dataset_attach_tag] + From 9674e9dd4c1c01c4034a2455e57bad0e4c2eb545 Mon Sep 17 00:00:00 2001 From: pratikmore0290 Date: Thu, 29 Aug 2024 23:02:04 +0000 Subject: [PATCH 2/4] feat(bigquery): Add example for creating a dataset with tag attached --- bigquery/bigquery_create_dataset_attach_tag/main.tf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bigquery/bigquery_create_dataset_attach_tag/main.tf b/bigquery/bigquery_create_dataset_attach_tag/main.tf index aaa1f7b12..063ccb0b6 100644 --- a/bigquery/bigquery_create_dataset_attach_tag/main.tf +++ b/bigquery/bigquery_create_dataset_attach_tag/main.tf @@ -16,6 +16,7 @@ # [START bigquery_create_dataset_attach_tag] +# Create tag keys and values data "google_project" "default" {} resource "google_tags_tag_key" "env_tag_key" { @@ -38,6 +39,7 @@ resource "google_tags_tag_value" "department_tag_value" { short_name = "sales" } +# Create a dataset resource "google_bigquery_dataset" "default" { dataset_id = "my_dataset" default_partition_expiration_ms = 2592000000 # 30 days @@ -46,11 +48,10 @@ resource "google_bigquery_dataset" "default" { location = "US" max_time_travel_hours = 96 # 4 days - # Create a dataset with resource_tags + # Attach tags to the dataset resource_tags = { "${google_tags_tag_key.env_tag_key.namespaced_name}" : "${google_tags_tag_value.env_tag_value.short_name}", "${google_tags_tag_key.department_tag_key.namespaced_name}" : "${google_tags_tag_value.department_tag_value.short_name}" } } -# [END bigquery_create_dataset_attach_tag] - +# [END bigquery_create_dataset_attach_tag] \ No newline at end of file From 8ecb8ad0c104e1a698edaff8cc10552406a418e9 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Fri, 30 Aug 2024 14:24:17 +1000 Subject: [PATCH 3/4] Update bigquery/bigquery_create_dataset_attach_tag/main.tf --- bigquery/bigquery_create_dataset_attach_tag/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigquery/bigquery_create_dataset_attach_tag/main.tf b/bigquery/bigquery_create_dataset_attach_tag/main.tf index 063ccb0b6..0f852e87f 100644 --- a/bigquery/bigquery_create_dataset_attach_tag/main.tf +++ b/bigquery/bigquery_create_dataset_attach_tag/main.tf @@ -54,4 +54,4 @@ resource "google_bigquery_dataset" "default" { "${google_tags_tag_key.department_tag_key.namespaced_name}" : "${google_tags_tag_value.department_tag_value.short_name}" } } -# [END bigquery_create_dataset_attach_tag] \ No newline at end of file +# [END bigquery_create_dataset_attach_tag] From f8ca53007d67a23912dba2dd916821aedcb4bf42 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Fri, 30 Aug 2024 14:51:44 +1000 Subject: [PATCH 4/4] lint --- bigquery/bigquery_create_dataset_attach_tag/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bigquery/bigquery_create_dataset_attach_tag/main.tf b/bigquery/bigquery_create_dataset_attach_tag/main.tf index 0f852e87f..e46ddcfa0 100644 --- a/bigquery/bigquery_create_dataset_attach_tag/main.tf +++ b/bigquery/bigquery_create_dataset_attach_tag/main.tf @@ -50,8 +50,8 @@ resource "google_bigquery_dataset" "default" { # Attach tags to the dataset resource_tags = { - "${google_tags_tag_key.env_tag_key.namespaced_name}" : "${google_tags_tag_value.env_tag_value.short_name}", - "${google_tags_tag_key.department_tag_key.namespaced_name}" : "${google_tags_tag_value.department_tag_value.short_name}" + (google_tags_tag_key.env_tag_key.namespaced_name) : google_tags_tag_value.env_tag_value.short_name, + (google_tags_tag_key.department_tag_key.namespaced_name) : google_tags_tag_value.department_tag_value.short_name } } # [END bigquery_create_dataset_attach_tag]