Skip to content

Commit

Permalink
Add PubSub action to DLP Job Trigger (#6757)
Browse files Browse the repository at this point in the history
  • Loading branch information
soumya92 authored Nov 2, 2022
1 parent 7d31ece commit 1acec00
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mmv1/products/dlp/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}

0 comments on commit 1acec00

Please sign in to comment.