magic-modules icon indicating copy to clipboard operation
magic-modules copied to clipboard

add `dataGovernanceType` field to `bigquery_routine` resource

Open BBBmau opened this issue 1 year ago • 28 comments

Fixes https://github.com/hashicorp/terraform-provider-google/issues/17061

Release Note Template for Downstream PRs (will be copied)

bigquery: added `dataGovernanceType` to `google_bigquery_routine` resource

BBBmau avatar Jan 22 '24 22:01 BBBmau

Tests analytics

Total tests: 107 Passed tests 99 Skipped tests: 8 Affected tests: 0

Click here to see the affected service packages
  • bigquery

$\textcolor{green}{\textsf{All tests passed in REPLAYING mode.}}$ View the build log

modular-magician avatar Jan 22 '24 22:01 modular-magician

simple field add, should be ready to merge.

BBBmau avatar Jan 25 '24 17:01 BBBmau

@c2thorn added, the example comes from the custom mask docs

BBBmau avatar Jan 26 '24 18:01 BBBmau

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 97 insertions(+)) Terraform Beta: Diff ( 3 files changed, 97 insertions(+)) TF Conversion: Diff ( 1 file changed, 10 insertions(+)) TF OiCS: Diff ( 4 files changed, 113 insertions(+))

modular-magician avatar Jan 26 '24 18:01 modular-magician

Tests analytics

Total tests: 108 Passed tests 99 Skipped tests: 8 Affected tests: 1

Click here to see the affected service packages
  • bigquery

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample

Get to know how VCR tests work

modular-magician avatar Jan 26 '24 18:01 modular-magician

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$ TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$ View the build log or the debug log for each test

modular-magician avatar Jan 26 '24 18:01 modular-magician

        Error: Error creating Routine: googleapi: Error 400: Unknown option: data_governance_type, invalidQuery

c2thorn avatar Jan 26 '24 18:01 c2thorn

weird error since its stating that data_governance_type doesn't exist as a type but the docs shows it as a valid entry for OPTIONS

CREATE OR REPLACE FUNCTION SSN_Mask(ssn STRING) RETURNS STRING OPTIONS (data_governance_type="DATA_MASKING") AS ( SAFE.REGEXP_REPLACE(ssn, '[0-9]', 'X') # 123-45-6789 -> XXX-XX-XXXX );

BBBmau avatar Jan 26 '24 19:01 BBBmau

I believe the feature is in the Preview launch stage (see "In Preview." at https://cloud.google.com/bigquery/docs/column-data-masking-intro#masking_options) and may need an explicit opt-in for the GCP project. @BBBmau were you able to get it to work with DDL in your project and what did you do to get on an allowlist?

wj-chen avatar Jan 26 '24 23:01 wj-chen

The custom data masking feature was made generally available (GA) on 2/8: https://cloud.google.com/bigquery/docs/release-notes#February_08_2024. Let's rerun the tests to see if the API 400 error is no longer applicable.

wj-chen avatar Feb 27 '24 05:02 wj-chen

/gcbrun

wj-chen avatar Feb 27 '24 05:02 wj-chen

The custom data masking feature was made generally available (GA) on 2/8: https://cloud.google.com/bigquery/docs/release-notes#February_08_2024. Let's rerun the tests to see if the API 400 error is no longer applicable.

@BBBmau This PR could use a merge from main. Do you still have some bandwidth to work on this?

wj-chen avatar Feb 27 '24 05:02 wj-chen

/gcbrun

c2thorn avatar Feb 27 '24 16:02 c2thorn

There's a file conflict that may stop the build before the test runs.

c2thorn avatar Feb 27 '24 16:02 c2thorn

/gcbrun

BBBmau avatar Feb 27 '24 16:02 BBBmau

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 97 insertions(+)) Terraform Beta: Diff ( 3 files changed, 97 insertions(+)) TF Conversion: Diff ( 1 file changed, 10 insertions(+)) TF OiCS: Diff ( 4 files changed, 113 insertions(+))

modular-magician avatar Feb 27 '24 17:02 modular-magician

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 97 insertions(+)) Terraform Beta: Diff ( 3 files changed, 97 insertions(+)) TF Conversion: Diff ( 1 file changed, 10 insertions(+)) TF OiCS: Diff ( 4 files changed, 113 insertions(+))

modular-magician avatar Feb 27 '24 17:02 modular-magician

Tests analytics

Total tests: 110 Passed tests: 101 Skipped tests: 8 Affected tests: 1

Click here to see the affected service packages
  • bigquery

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample

Get to know how VCR tests work

modular-magician avatar Feb 27 '24 17:02 modular-magician

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$ TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$ View the build log or the debug log for each test

modular-magician avatar Feb 27 '24 17:02 modular-magician

Tests analytics

Total tests: 110 Passed tests: 101 Skipped tests: 8 Affected tests: 1

Click here to see the affected service packages
  • bigquery

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample

Get to know how VCR tests work

modular-magician avatar Feb 27 '24 17:02 modular-magician

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$ TestAccBigQueryRoutine_bigQueryRoutineDataGovernanceTypeExample[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$ View the build log or the debug log for each test

modular-magician avatar Feb 27 '24 17:02 modular-magician

        Error: Error creating Routine: googleapi: Error 400: Project ID, dataset ID and routine ID cannot be missing or empty in call to routines.insert, invalid
        
          with google_bigquery_routine.sproc,
          on terraform_plugin_test.tf line 6, in resource "google_bigquery_routine" "sproc":
           6: resource "google_bigquery_routine" "sproc" {
           ```

BBBmau avatar Feb 27 '24 17:02 BBBmau

        Error: Error creating Routine: googleapi: Error 400: Project ID, dataset ID and routine ID cannot be missing or empty in call to routines.insert, invalid
        
          with google_bigquery_routine.sproc,
          on terraform_plugin_test.tf line 6, in resource "google_bigquery_routine" "sproc":
           6: resource "google_bigquery_routine" "sproc" {
           ```

From the debug logs:

---[ REQUEST ]---------------------------------------
POST /bigquery/v2/projects/<project-id>/datasets/tf_test_dataset_id0c7gks16bz/routines?alt=json HTTP/1.1
Host: bigquery.googleapis.com
User-Agent: Terraform/1.2.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.31.0 terraform-provider-google-beta/acc
Content-Length: 313
Content-Type: application/json
Accept-Encoding: gzip

{
 "dataGovernanceType": "DATA_MASKING",
 "definitionBody": "CREATE FUNCTION SSN_Mask(ssn STRING) RETURNS STRING AS (SAFE.REGEXP_REPLACE(ssn, '[0-9]', 'x'));",
 "language": "SQL",
 "routineReference": {
  "datasetId": "tf_test_dataset_id0c7gks16bz",
  "projectId": "<project-id>",
  "routineId": ""
 },
 "routineType": "PROCEDURE"
}

routineId was empty.

I added a comment to the PR which should help resolve this.

wj-chen avatar Feb 27 '24 18:02 wj-chen

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 3 files changed, 97 insertions(+)) Terraform Beta: Diff ( 3 files changed, 97 insertions(+)) TF Conversion: Diff ( 1 file changed, 10 insertions(+)) TF OiCS: Diff ( 4 files changed, 113 insertions(+))

modular-magician avatar Feb 27 '24 19:02 modular-magician

Tests analytics

Total tests: 110 Passed tests: 101 Skipped tests: 8 Affected tests: 1

Click here to see the affected service packages
  • bigquery

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccBigQueryRoutine_bigqueryRoutineDataGovernanceTypeExample

Get to know how VCR tests work

modular-magician avatar Feb 27 '24 19:02 modular-magician

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$ TestAccBigQueryRoutine_bigqueryRoutineDataGovernanceTypeExample[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$ View the build log or the debug log for each test

modular-magician avatar Feb 27 '24 19:02 modular-magician

back to the original error

BBBmau avatar Feb 27 '24 20:02 BBBmau

back to the original error

The code change looks good. I will circle back after reach out to the BQ Routines team on the NotFound error.

wj-chen avatar Feb 27 '24 20:02 wj-chen

back to the original error

The code change looks good. I will circle back after reach out to the BQ Routines team on the NotFound error.

I got this guidance: "The data_masking_type is only supported for scalar functions. The request has a procedure."

Could you try with a config with routine_type = "SCALAR_FUNCTION" and a simple scalar function?

wj-chen avatar Mar 05 '24 04:03 wj-chen

@wj-chen attempted several different functions but an unexpected keyword error would appear:

=== CONT  TestAccBigQueryRoutine_bigqueryRoutineDataGovernanceTypeExample
    vcr_utils.go:152: Step 1/2 error: Error running apply: exit status 1
        
        Error: Error creating Routine: googleapi: Error 400: Syntax error: Unexpected keyword CREATE at [1:1], invalidQuery
        
          with google_bigquery_routine.sproc,
          on terraform_plugin_test.tf line 6, in resource "google_bigquery_routine" "sproc":
           6: resource "google_bigquery_routine" "sproc" {
        
--- FAIL: TestAccBigQueryRoutine_bigqueryRoutineDataGovernanceTypeExample (7.76s)

BBBmau avatar Mar 05 '24 20:03 BBBmau