|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +package securitycenter_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
| 10 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| 11 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAccSecurityCenterFolderBigQueryExportConfig_update(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + randomSuffix := acctest.RandString(t, 10) |
| 18 | + dataset_id := "tf_test_" + randomSuffix |
| 19 | + dataset_id2 := dataset_id + "2" |
| 20 | + orgID := envvar.GetTestOrgFromEnv(t) |
| 21 | + |
| 22 | + context := map[string]interface{}{ |
| 23 | + "org_id": orgID, |
| 24 | + "random_suffix": randomSuffix, |
| 25 | + "dataset_id": dataset_id, |
| 26 | + "dataset_id2": dataset_id2, |
| 27 | + "big_query_export_id": "tf-test-export-" + randomSuffix, |
| 28 | + "folder_name": "tf-test-folder-name-" + randomSuffix, |
| 29 | + } |
| 30 | + |
| 31 | + acctest.VcrTest(t, resource.TestCase{ |
| 32 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 33 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 34 | + ExternalProviders: map[string]resource.ExternalProvider{ |
| 35 | + "time": {}, |
| 36 | + }, |
| 37 | + Steps: []resource.TestStep{ |
| 38 | + { |
| 39 | + Config: testAccSecurityCenterFolderBigQueryExportConfig_basic(context), |
| 40 | + }, |
| 41 | + { |
| 42 | + ResourceName: "google_scc_folder_scc_big_query_export.default", |
| 43 | + ImportState: true, |
| 44 | + ImportStateVerify: true, |
| 45 | + ImportStateVerifyIgnore: []string{"update_time"}, |
| 46 | + }, |
| 47 | + { |
| 48 | + Config: testAccSecurityCenterFolderBigQueryExportConfig_update(context), |
| 49 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 50 | + PreApply: []plancheck.PlanCheck{ |
| 51 | + plancheck.ExpectResourceAction("google_scc_folder_scc_big_query_export.default", plancheck.ResourceActionUpdate), |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + { |
| 56 | + ResourceName: "google_scc_folder_scc_big_query_export.default", |
| 57 | + ImportState: true, |
| 58 | + ImportStateVerify: true, |
| 59 | + ImportStateVerifyIgnore: []string{"update_time"}, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +func testAccSecurityCenterFolderBigQueryExportConfig_basic(context map[string]interface{}) string { |
| 66 | + return acctest.Nprintf(` |
| 67 | +resource "google_folder" "folder" { |
| 68 | + parent = "organizations/%{org_id}" |
| 69 | + display_name = "%{folder_name}" |
| 70 | + deletion_protection = false |
| 71 | +} |
| 72 | +resource "google_bigquery_dataset" "default" { |
| 73 | + dataset_id = "%{dataset_id}" |
| 74 | + friendly_name = "test" |
| 75 | + description = "This is a test description" |
| 76 | + location = "US" |
| 77 | + default_table_expiration_ms = 3600000 |
| 78 | + default_partition_expiration_ms = null |
| 79 | + labels = { |
| 80 | + env = "default" |
| 81 | + } |
| 82 | + lifecycle { |
| 83 | + ignore_changes = [default_partition_expiration_ms] |
| 84 | + } |
| 85 | +} |
| 86 | +resource "time_sleep" "wait_1_minute" { |
| 87 | + depends_on = [google_bigquery_dataset.default] |
| 88 | + create_duration = "3m" |
| 89 | +} |
| 90 | +resource "google_scc_folder_scc_big_query_export" "default" { |
| 91 | + big_query_export_id = "%{big_query_export_id}" |
| 92 | + folder = google_folder.folder.folder_id |
| 93 | + dataset = google_bigquery_dataset.default.id |
| 94 | + description = "Cloud Security Command Center Findings Big Query Export Config" |
| 95 | + filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\"" |
| 96 | +
|
| 97 | + depends_on = [time_sleep.wait_1_minute] |
| 98 | +} |
| 99 | +
|
| 100 | +`, context) |
| 101 | +} |
| 102 | + |
| 103 | +func testAccSecurityCenterFolderBigQueryExportConfig_update(context map[string]interface{}) string { |
| 104 | + return acctest.Nprintf(` |
| 105 | +resource "google_folder" "folder" { |
| 106 | + parent = "organizations/%{org_id}" |
| 107 | + display_name = "%{folder_name}" |
| 108 | + deletion_protection = false |
| 109 | +} |
| 110 | +resource "google_bigquery_dataset" "default" { |
| 111 | + dataset_id = "%{dataset_id2}" |
| 112 | + friendly_name = "test" |
| 113 | + description = "This is a test description" |
| 114 | + location = "US" |
| 115 | + default_table_expiration_ms = 3600000 |
| 116 | + default_partition_expiration_ms = null |
| 117 | + labels = { |
| 118 | + env = "default" |
| 119 | + } |
| 120 | + lifecycle { |
| 121 | + ignore_changes = [default_partition_expiration_ms] |
| 122 | + } |
| 123 | +} |
| 124 | +resource "google_scc_folder_scc_big_query_export" "default" { |
| 125 | + big_query_export_id = "%{big_query_export_id}" |
| 126 | + folder = google_folder.folder.folder_id |
| 127 | + dataset = google_bigquery_dataset.default.id |
| 128 | + description = "SCC Findings Big Query Export Update" |
| 129 | + filter = "" |
| 130 | +} |
| 131 | +
|
| 132 | +`, context) |
| 133 | +} |
0 commit comments