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