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 PubSub action to DLP Job Trigger #6757

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
soumya92 marked this conversation as resolved.
Show resolved Hide resolved
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)
}