| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| package securitycenter_test |
| |
| import ( |
| "testing" |
| |
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" |
| ) |
| |
| func TestAccSecurityCenterNotificationConfig_updateStreamingConfigFilter(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "org_id": envvar.GetTestOrgFromEnv(t), |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| CheckDestroy: testAccCheckSecurityCenterNotificationConfigDestroyProducer(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccSecurityCenterNotificationConfig_sccNotificationConfigBasicExample(context), |
| }, |
| { |
| ResourceName: "google_scc_notification_config.custom_notification_config", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"organization", "config_id"}, |
| }, |
| { |
| Config: testAccSecurityCenterNotificationConfig_updateStreamingConfigFilter(context), |
| }, |
| { |
| ResourceName: "google_scc_notification_config.custom_notification_config", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"organization", "config_id"}, |
| }, |
| { |
| Config: testAccSecurityCenterNotificationConfig_emptyStreamingConfigFilter(context), |
| }, |
| { |
| ResourceName: "google_scc_notification_config.custom_notification_config", |
| ImportState: true, |
| ImportStateVerify: true, |
| ImportStateVerifyIgnore: []string{"organization", "config_id"}, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccSecurityCenterNotificationConfig_updateStreamingConfigFilter(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_pubsub_topic" "scc_notification" { |
| name = "tf-test-my-topic%{random_suffix}" |
| } |
| |
| resource "google_scc_notification_config" "custom_notification_config" { |
| config_id = "tf-test-my-config%{random_suffix}" |
| organization = "%{org_id}" |
| description = "My custom Cloud Security Command Center Finding Notification Configuration" |
| pubsub_topic = google_pubsub_topic.scc_notification.id |
| |
| streaming_config { |
| filter = "category = \"OPEN_FIREWALL\"" |
| } |
| } |
| `, context) |
| } |
| |
| func testAccSecurityCenterNotificationConfig_emptyStreamingConfigFilter(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| resource "google_pubsub_topic" "scc_notification" { |
| name = "tf-test-my-topic%{random_suffix}" |
| } |
| |
| resource "google_scc_notification_config" "custom_notification_config" { |
| config_id = "tf-test-my-config%{random_suffix}" |
| organization = "%{org_id}" |
| description = "My custom Cloud Security Command Center Finding Notification Configuration" |
| pubsub_topic = google_pubsub_topic.scc_notification.id |
| |
| streaming_config { |
| filter = "" |
| } |
| } |
| `, context) |
| } |