From 544de4028bfee03dbd86a24aba53bdb234a05608 Mon Sep 17 00:00:00 2001 From: Soumya Date: Fri, 28 Oct 2022 16:54:38 -0700 Subject: [PATCH] Add pubsub action to job trigger --- mmv1/products/dlp/api.yaml | 17 +++++- ...e_data_loss_prevention_job_trigger_test.go | 57 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/mmv1/products/dlp/api.yaml b/mmv1/products/dlp/api.yaml index 129513aaa4e2..28d4a825ead3 100644 --- a/mmv1/products/dlp/api.yaml +++ b/mmv1/products/dlp/api.yaml @@ -297,7 +297,9 @@ objects: properties: - !ruby/object:Api::Type::NestedObject name: 'saveFindings' - required: true + exactly_one_of: + - save_findings + - pub_sub description: | Schedule for triggered jobs properties: @@ -345,6 +347,19 @@ objects: - :DATASTORE_COLUMNS - :BIG_QUERY_COLUMNS - :ALL_COLUMNS + - !ruby/object:Api::Type::NestedObject + name: 'pubSub' + exactly_one_of: + - save_findings + - pub_sub + description: | + Publish a message into a given Pub/Sub topic when the job completes. + properties: + - !ruby/object:Api::Type::String + name: 'topic' + required: true + description: | + Cloud Pub/Sub topic to send notifications to. - !ruby/object:Api::Resource name: 'InspectTemplate' create_url: "{{parent}}/inspectTemplates" diff --git a/mmv1/third_party/terraform/tests/resource_data_loss_prevention_job_trigger_test.go b/mmv1/third_party/terraform/tests/resource_data_loss_prevention_job_trigger_test.go index 7b057409ff49..b38fa383a251 100644 --- a/mmv1/third_party/terraform/tests/resource_data_loss_prevention_job_trigger_test.go +++ b/mmv1/third_party/terraform/tests/resource_data_loss_prevention_job_trigger_test.go @@ -41,6 +41,31 @@ func TestAccDataLossPreventionJobTrigger_dlpJobTriggerUpdateExample(t *testing.T }) } +func TestAccDataLossPreventionJobTrigger_dlpJobTriggerPubsub(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project": getTestProjectFromEnv(), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDataLossPreventionJobTriggerDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDataLossPreventionJobTrigger_publishToPubSub(context), + }, + { + ResourceName: "google_data_loss_prevention_job_trigger.pubsub", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent"}, + }, + }, + }) +} + func testAccDataLossPreventionJobTrigger_dlpJobTriggerBasic(context map[string]interface{}) string { return Nprintf(` resource "google_data_loss_prevention_job_trigger" "basic" { @@ -114,3 +139,35 @@ resource "google_data_loss_prevention_job_trigger" "basic" { } `, context) } + +func testAccDataLossPreventionJobTrigger_publishToPubSub(context map[string]interface{}) string { + return Nprintf(` +resource "google_data_loss_prevention_job_trigger" "pubsub" { + parent = "projects/%{project}" + description = "Starting description" + display_name = "display" + + triggers { + schedule { + recurrence_period_duration = "86400s" + } + } + + inspect_job { + inspect_template_name = "fake" + actions { + pub_sub { + topic = "projects/%{project}/topics/bar" + } + } + storage_config { + cloud_storage_options { + file_set { + url = "gs://mybucket/directory/" + } + } + } + } +} +`, context) +}