Skip to content

Commit 7c9be60

Browse files
feat(bigquery): Add example for creating a table with tag attached (#734)
* feat(bigquery): Add example for creating a table with tag attached * lint: fix newline whitespace * lint: unrequired string interpolation * lint fix * add skip test with note about provider issue --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent f529f61 commit 7c9be60

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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_table_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 = "env3"
25+
}
26+
27+
resource "google_tags_tag_key" "department_tag_key" {
28+
parent = "projects/${data.google_project.default.project_id}"
29+
short_name = "department3"
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 = "MyDataset"
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+
52+
# Create a table
53+
resource "google_bigquery_table" "default" {
54+
dataset_id = google_bigquery_dataset.default.dataset_id
55+
table_id = "mytable"
56+
description = "table description"
57+
deletion_protection = false # set to "true" in production
58+
59+
# Attach tags to the table
60+
resource_tags = {
61+
(google_tags_tag_key.env_tag_key.namespaced_name) : google_tags_tag_value.env_tag_value.short_name,
62+
(google_tags_tag_key.department_tag_key.namespaced_name) : google_tags_tag_value.department_tag_value.short_name
63+
}
64+
}
65+
# [END bigquery_create_table_attach_tag]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: bigquery_bigquery_create_table_attach_tag
19+
spec:
20+
skip: true
21+
22+
# https://github.com/hashicorp/terraform-provider-google/issues/19362

0 commit comments

Comments
 (0)