Skip to content

Commit 2435e01

Browse files
feat(bigquery): Add example for creating a dataset with tag attached (#733)
* feat(bigquery): Add example for creating a dataset with tag attached * feat(bigquery): Add example for creating a dataset with tag attached * Update bigquery/bigquery_create_dataset_attach_tag/main.tf --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent b49d6db commit 2435e01

File tree

1 file changed

+57
-0
lines changed
  • bigquery/bigquery_create_dataset_attach_tag

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START bigquery_create_dataset_attach_tag]
18+
19+
# Create tag keys and values
20+
data "google_project" "default" {}
21+
22+
resource "google_tags_tag_key" "env_tag_key" {
23+
parent = "projects/${data.google_project.default.project_id}"
24+
short_name = "env2"
25+
}
26+
27+
resource "google_tags_tag_key" "department_tag_key" {
28+
parent = "projects/${data.google_project.default.project_id}"
29+
short_name = "department2"
30+
}
31+
32+
resource "google_tags_tag_value" "env_tag_value" {
33+
parent = "tagKeys/${google_tags_tag_key.env_tag_key.name}"
34+
short_name = "prod"
35+
}
36+
37+
resource "google_tags_tag_value" "department_tag_value" {
38+
parent = "tagKeys/${google_tags_tag_key.department_tag_key.name}"
39+
short_name = "sales"
40+
}
41+
42+
# Create a dataset
43+
resource "google_bigquery_dataset" "default" {
44+
dataset_id = "my_dataset"
45+
default_partition_expiration_ms = 2592000000 # 30 days
46+
default_table_expiration_ms = 31536000000 # 365 days
47+
description = "dataset description"
48+
location = "US"
49+
max_time_travel_hours = 96 # 4 days
50+
51+
# Attach tags to the dataset
52+
resource_tags = {
53+
(google_tags_tag_key.env_tag_key.namespaced_name) : google_tags_tag_value.env_tag_value.short_name,
54+
(google_tags_tag_key.department_tag_key.namespaced_name) : google_tags_tag_value.department_tag_value.short_name
55+
}
56+
}
57+
# [END bigquery_create_dataset_attach_tag]

0 commit comments

Comments
 (0)