-
Notifications
You must be signed in to change notification settings - Fork 286
feat(bigquery): adds Bigquery datapolicies samples for C.G.C. documentation #902
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Copyright 2025 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_datapolicies_create_custom_masking_policy] | ||
| resource "google_bigquery_dataset" "default" { | ||
| dataset_id = "mydataset" | ||
| location = "US" | ||
| } | ||
|
|
||
| resource "google_bigquery_routine" "default" { | ||
| dataset_id = google_bigquery_dataset.default.dataset_id | ||
| routine_id = "custom_masking_routine" | ||
| routine_type = "SCALAR_FUNCTION" | ||
| language = "SQL" | ||
| data_governance_type = "DATA_MASKING" | ||
| definition_body = "SAFE.REGEXP_REPLACE(ssn, '[0-9]', 'X')" | ||
| return_type = "{\"typeKind\" : \"STRING\"}" | ||
|
|
||
| arguments { | ||
| name = "ssn" | ||
| data_type = "{\"typeKind\" : \"STRING\"}" | ||
| } | ||
| } | ||
|
|
||
| resource "google_bigquery_datapolicyv2_data_policy" "default" { | ||
| location = "US" | ||
| data_policy_id = "custom_masking_policy" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value used here looks too close to the faux enum in the next like. Could it be changed to "my_custom_policy" or similar? |
||
| data_policy_type = "DATA_MASKING_POLICY" | ||
| data_masking_policy { | ||
| routine = google_bigquery_routine.default.id | ||
| } | ||
| } | ||
| # [END bigquery_datapolicies_create_custom_masking_policy] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright 2025 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_datapolicies_create_raw_data_access_policy] | ||
| resource "google_bigquery_datapolicyv2_data_policy" "default" { | ||
| location = "US" | ||
| data_policy_type = "RAW_DATA_ACCESS_POLICY" | ||
| grantees = [ | ||
| "principal://goog/subject/raha@altostrat.com" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This princpal has been referenced in a handful of other BigQuery samples. Is this a testing account? Could it be replaced with a more obvious testing value? |
||
| ] | ||
| data_policy_id = "raw_policy" | ||
| } | ||
| # [END bigquery_datapolicies_create_raw_data_access_policy] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright 2025 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_datapolicies_create_predefined_masking_policy] | ||
| resource "google_bigquery_datapolicyv2_data_policy" "default" { | ||
| location = "US" | ||
| data_policy_type = "DATA_MASKING_POLICY" | ||
| data_masking_policy { | ||
| predefined_expression = "SHA256" | ||
| } | ||
| data_policy_id = "predefined_masking_policy" | ||
| } | ||
| # [END bigquery_datapolicies_create_predefined_masking_policy] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Copyright 2025 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_datapolicies_create_raw_data_access_policy] | ||
| resource "google_bigquery_datapolicyv2_data_policy" "default" { | ||
| location = "US" | ||
| data_policy_type = "RAW_DATA_ACCESS_POLICY" | ||
| data_policy_id = "raw_policy" | ||
| } | ||
| # [END bigquery_datapolicies_create_raw_data_access_policy] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this has to be an escape-encoded string, and not use
jsonencode?Same for the arguments.data_type.