Skip to content
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

Add two outputs for dlp job trigger: outputting to SCC and DataCatalog #6855

Merged
merged 6 commits into from
Jan 24, 2023

Conversation

Wallace99
Copy link
Contributor

@Wallace99 Wallace99 commented Nov 21, 2022

Add in outputting results of DLP job to SCC and DataCatalog. Also fix description of saveFindings block and remove unnecessary restriction on only one output.

Fixes hashicorp/terraform-provider-google#11861

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform, and ran make test and make lint to ensure it passes unit and linter tests.
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Ran relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

dlp: added `publish_findings_to_cloud_data_catalog` and `publish_summary_to_cscc` to `google_data_loss_prevention_job_trigger` resource

@modular-magician
Copy link
Collaborator

Oops! It looks like you're using an unknown release-note type in your changelog entries:

  • enhancement New outputs for DLP inspection trigger

Please only use the types listed in https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I've detected that you're a community contributor. @shuyama1, a repository maintainer, has been assigned to assist you and help review your changes.

❓ First time contributing? Click here for more details

Your assigned reviewer will help review your code by:

  • Ensuring it's backwards compatible, covers common error cases, etc.
  • Summarizing the change into a user-facing changelog note.
  • Passes tests, either our "VCR" suite, a set of presubmit tests, or with manual test runs.

You can help make sure that review is quick by running local tests and ensuring they're passing in between each push you make to your PR's branch. Also, try to leave a comment with each push you make, as pushes generally don't generate emails.

If your reviewer doesn't get back to you within a week after your most recent change, please feel free to leave a comment on the issue asking them to take a look! In the absence of a dedicated review dashboard most maintainers manage their pending reviews through email, and those will sometimes get lost in their inbox.


Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wallace99 Thanks for making the change! The build failed due to

bundler: failed to load command: compiler (compiler)
RuntimeError: Field 'publish_summary_to_cscc' properties are nil!

Looks like publishSummaryToCscc and publishFindingsToCloudDataCatalog are added as nested object without subfields which will cause the build fail. Maybe consider adding some virtual subfields such as boolean field enable to make sure nested object are non-empty?

@Wallace99
Copy link
Contributor Author

@Wallace99 Thanks for making the change! The build failed due to

bundler: failed to load command: compiler (compiler)
RuntimeError: Field 'publish_summary_to_cscc' properties are nil!

Looks like publishSummaryToCscc and publishFindingsToCloudDataCatalog are added as nested object without subfields which will cause the build fail. Maybe consider adding some virtual subfields such as boolean field enable to make sure nested object are non-empty?

Ah thanks, will update that shortly!

@Wallace99
Copy link
Contributor Author

Hi @shuyama1, sorry for the delay. Do you know of elsewhere in the repo I could reference for adding virtual subfields? Would some custom logic also be needed? To configure a DLP inspection job to output to SCC an empty JSON object called publishSummaryToCscc is added to the actions array, and if it's not there it doesn't send to SCC (likewise for Data Catalog). If we add a virtual field called enabled for example, will the empty JSON object still be added if enabled is set to false by the user? Perhaps I'm misunderstanding what virtual subfields are?

@shuyama1
Copy link
Member

Hi @Wallace99, it seems that we may be able handle empty block schema by adding properties: [] to the nested field in the api.yaml, for example https://github.com/GoogleCloudPlatform/magic-modules/blame/main/mmv1/products/vertexai/api.yaml#L938. Would you mind trying that first and see if it works?

@shuyama1
Copy link
Member

/gcbrun

@modular-magician
Copy link
Collaborator

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, 100 insertions(+), 6 deletions(-))
Terraform Beta: Diff ( 3 files changed, 100 insertions(+), 6 deletions(-))
TF Validator: Diff ( 3 files changed, 47 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2340
Passed tests 2091
Skipped tests: 244
Failed tests: 5

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccLoggingBucketConfigProject_cmekSettings|TestAccDataLossPreventionJobTrigger_dlpJobTriggerUpdateExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBasicExample

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccLoggingBucketConfigProject_cmekSettings[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerUpdateExample[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBasicExample[Debug log]

Tests failed during RECORDING mode:
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample[Error message] [Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

@shuyama1
Copy link
Member

Hi @Wallace99! Would you mind also modifying the changelog a bit based on https://github.com/GoogleCloudPlatform/magic-modules/blob/main/.ci/RELEASE_NOTES_GUIDE.md? Thanks!

Co-authored-by: Shuya Ma <87669292+shuyama1@users.noreply.github.com>
@modular-magician
Copy link
Collaborator

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, 100 insertions(+), 6 deletions(-))
Terraform Beta: Diff ( 3 files changed, 100 insertions(+), 6 deletions(-))
TF Validator: Diff ( 3 files changed, 47 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2344
Passed tests 2094
Skipped tests: 246
Failed tests: 4

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample|TestAccLoggingBucketConfigProject_cmekSettings|TestAccFirebaserulesRelease_BasicRelease

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccLoggingBucketConfigProject_cmekSettings[Debug log]
TestAccFirebaserulesRelease_BasicRelease[Debug log]

Tests failed during RECORDING mode:
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample[Error message] [Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like only one of the fields in actions can be specified. Therefore, I propose we add back exactly_one_of and also include the newly added two fields. Plus, we need to use indexed path for exactly_one_of (save_findings -> inspect_job.0.actions.0.save_findings).

Would you mind testing it locally first to make sure the test passed? It will be faster to see tests result running locally as our CI need to run the PR against the whole test suite.

@Wallace99
Copy link
Contributor Author

The docs for the DLP rest api do say only one action can be specified, but I believe they're incorrect as I can create an inspection trigger with multiple actions both through the rest api and through the console. That's why I removed exactly_one_of as it's unnecessarily restrictive - there's no reason I can think of why someone shouldn't be able to output their results to SCC as well as to BigQuery for example. I left feedback on the DLP docs page, but I might try and contact them directly to get them to correct the docs or clarify whether it's actually intended to be able to only output to one place.

But yes, sorry I will locally test first! I've been having issues getting the tests to run locally so hoped this would be a trivial change that passed first try 😄

@shuyama1
Copy link
Member

@Wallace99 Thanks for the explanation! Please let me know when you hear back from the API team, as based on the current error for the failed test, it seems that it still does not allow multiple actions to be set at the same time:

    provider_test.go:315: Step 1/2 error: Error running apply: exit status 1
        
        Error: Error creating JobTrigger: googleapi: Error 400: Invalid value at 'job_trigger.inspect_job.actions[0]' (oneof), oneof field 'action' is already set. Cannot set 'saveFindings'
        Details:
        [
          {
            "@type": "type.googleapis.com/google.rpc.BadRequest",
            "fieldViolations": [
              {
                "description": "Invalid value at 'job_trigger.inspect_job.actions[0]' (oneof), oneof field 'action' is already set. Cannot set 'saveFindings'",
                "field": "job_trigger.inspect_job.actions[0]"
              }
            ]
          }
        ]
        
          with google_data_loss_prevention_job_trigger.bigquery_row_limit,
          on terraform_plugin_test.tf line 3, in resource "google_data_loss_prevention_job_trigger" "bigquery_row_limit":
           3: resource "google_data_loss_prevention_job_trigger" "bigquery_row_limit" {
        
--- FAIL: TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample (2.12s)

@Wallace99
Copy link
Contributor Author

Hi @shuyama1, my mistake - I meant to say the DLP Python client rather than the REST api. Just now I verified that I can create an inspection job trigger with two actions using the Python client which from a quick look appears to be calling the RPCs here. I'm confused as to why then the test would be failing with the message above. I opened a support case seeking clarification, but they said that it's intentional that the REST api (and RPCs) only allow one action and that there's an internal request for this to be changed, but there's no timeline for when it will be done.

I'm happy in the meantime to put back in exactly_one_of for actions to allow this PR and revisit it at a future point.

@shuyama1
Copy link
Member

@Wallace99 Thanks for the explanation. I'd propose to bring back exactly_one_of since the REST api only allows one action at this moment. We can drop the restriction when the API behavior is changed in the future. Thanks!

@modular-magician
Copy link
Collaborator

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 ( 2 files changed, 94 insertions(+), 4 deletions(-))
Terraform Beta: Diff ( 2 files changed, 94 insertions(+), 4 deletions(-))
TF Validator: Diff ( 3 files changed, 47 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2419
Passed tests 2163
Skipped tests: 252
Failed tests: 4

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccLoggingBucketConfigProject_cmekSettings|TestAccDataLossPreventionJobTrigger_dlpJobTriggerUpdateExample2|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccLoggingBucketConfigProject_cmekSettings[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerUpdateExample2[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitPercentageExample[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerBigqueryRowLimitExample[Debug log]

All tests passed
View the build log or the debug log for each test

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Only some nit-picks. Thank you for the work!

Comment on lines 2 to 31
parent = "projects/<%= ctx[:test_env_vars]['project'] %>"
description = "Description"
display_name = "Displayname"

triggers {
schedule {
recurrence_period_duration = "86400s"
}
}

inspect_job {
inspect_template_name = "fake"
actions {
publish_findings_to_cloud_data_catalog {
}
}
storage_config {
big_query_options {
table_reference {
project_id = "project"
dataset_id = "dataset"
table_id = "table_to_scan"
}

rows_limit_percent = 50
sample_method = "RANDOM_START"
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing is a bit off here - we use spaces instead of tabs for resource configuration for tests

Comment on lines 2 to 31
parent = "projects/<%= ctx[:test_env_vars]['project'] %>"
description = "Description"
display_name = "Displayname"

triggers {
schedule {
recurrence_period_duration = "86400s"
}
}

inspect_job {
inspect_template_name = "fake"
actions {
publish_summary_to_cscc {
}
}
storage_config {
big_query_options {
table_reference {
project_id = "project"
dataset_id = "dataset"
table_id = "table_to_scan"
}

rows_limit_percent = 50
sample_method = "RANDOM_START"
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing here

@modular-magician
Copy link
Collaborator

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 ( 2 files changed, 94 insertions(+), 4 deletions(-))
Terraform Beta: Diff ( 2 files changed, 94 insertions(+), 4 deletions(-))
TF Validator: Diff ( 3 files changed, 47 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2425
Passed tests 2170
Skipped tests: 253
Failed tests: 2

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccRegionInstanceGroupManager_stateful|TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample

@modular-magician
Copy link
Collaborator

Tests failed during RECORDING mode:
TestAccRegionInstanceGroupManager_stateful[Error message] [Debug log]
TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing tests are unrelated! Thank you for the work!

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I just realize that we didn't include the newly added examples to the terraform.yaml file, so no tests or doc examples is generated. Sorry for missing this earlier! I thought I saw related tests passed at some point but I guess those were only existing ones. Some examples of how to refer test/doc examples in the terraform.yaml file at https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/products/dlp/terraform.yaml#L76
Plus, I think we can fairly skip generating these two examples in the web docs by adding skip_docs: true in the terraform.yaml file. Please let me know if you have any question generating the tests. Thanks!

@modular-magician
Copy link
Collaborator

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, 216 insertions(+), 4 deletions(-))
Terraform Beta: Diff ( 3 files changed, 216 insertions(+), 4 deletions(-))
TF Validator: Diff ( 3 files changed, 47 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2425
Passed tests 2169
Skipped tests: 253
Failed tests: 3

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccDataLossPreventionJobTrigger_dlpJobTriggerSccOutputExample|TestAccDataLossPreventionJobTrigger_dlpJobTriggerDataCatalogOutputExample|TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccDataLossPreventionJobTrigger_dlpJobTriggerSccOutputExample[Debug log]
TestAccDataLossPreventionJobTrigger_dlpJobTriggerDataCatalogOutputExample[Debug log]

Tests failed during RECORDING mode:
TestAccCloudfunctions2function_cloudfunctions2BasicGcsExample[Error message] [Debug log]

Please fix these to complete your PR
View the build log or the debug log for each test

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for SCC Output to Cloud DLP Configuration
3 participants