Skip to content

Commit

Permalink
Fixed name of SCC v2 org bigquery export resource (#11661) (#8166)
Browse files Browse the repository at this point in the history
[upstream:b073e8765bbbb4d8878af5fa13eb1d9a9fb71f35]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 12, 2024
1 parent 39cff5e commit 541c568
Show file tree
Hide file tree
Showing 9 changed files with 983 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/11661.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:deprecation
securitycenterv2: deprecated `google_scc_v2_organization_scc_big_query_exports`. Use `google_scc_v2_organization_scc_big_query_export` instead.
```
5 changes: 3 additions & 2 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 515
// Generated resources: 516
// Generated IAM resources: 288
// Total generated resources: 803
// Total generated resources: 804
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -1180,6 +1180,7 @@ var generatedResources = map[string]*schema.Resource{
"google_scc_v2_folder_scc_big_query_export": securitycenterv2.ResourceSecurityCenterV2FolderSccBigQueryExport(),
"google_scc_v2_organization_mute_config": securitycenterv2.ResourceSecurityCenterV2OrganizationMuteConfig(),
"google_scc_v2_organization_notification_config": securitycenterv2.ResourceSecurityCenterV2OrganizationNotificationConfig(),
"google_scc_v2_organization_scc_big_query_export": securitycenterv2.ResourceSecurityCenterV2OrganizationSccBigQueryExport(),
"google_scc_v2_organization_scc_big_query_exports": securitycenterv2.ResourceSecurityCenterV2OrganizationSccBigQueryExports(),
"google_scc_v2_organization_source": securitycenterv2.ResourceSecurityCenterV2OrganizationSource(),
"google_scc_v2_organization_source_iam_binding": tpgiamresource.ResourceIamBinding(securitycenterv2.SecurityCenterV2OrganizationSourceIamSchema, securitycenterv2.SecurityCenterV2OrganizationSourceIamUpdaterProducer, securitycenterv2.SecurityCenterV2OrganizationSourceIdParseFunc),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAccSecurityCenterV2OrganizationBigQueryExportConfig_basic(t *testing.T)
Config: testAccSecurityCenterV2OrganizationBigQueryExportConfig_basic(context),
},
{
ResourceName: "google_scc_v2_organization_scc_big_query_exports.default",
ResourceName: "google_scc_v2_organization_scc_big_query_export.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
Expand All @@ -48,7 +48,7 @@ func TestAccSecurityCenterV2OrganizationBigQueryExportConfig_basic(t *testing.T)
Config: testAccSecurityCenterV2OrganizationBigQueryExportConfig_update(context),
},
{
ResourceName: "google_scc_v2_organization_scc_big_query_exports.default",
ResourceName: "google_scc_v2_organization_scc_big_query_export.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
Expand Down Expand Up @@ -82,7 +82,7 @@ resource "time_sleep" "wait_1_minute" {
create_duration = "3m"
}
resource "google_scc_v2_organization_scc_big_query_exports" "default" {
resource "google_scc_v2_organization_scc_big_query_export" "default" {
name = "%{name}"
big_query_export_id = "%{big_query_export_id}"
organization = "%{org_id}"
Expand All @@ -96,7 +96,7 @@ resource "google_scc_v2_organization_scc_big_query_exports" "default" {
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_organization_scc_big_query_exports.default]
depends_on = [google_scc_v2_organization_scc_big_query_export.default]
}
`, context)
}
Expand All @@ -121,7 +121,7 @@ resource "google_bigquery_dataset" "default" {
}
}
resource "google_scc_v2_organization_scc_big_query_exports" "default" {
resource "google_scc_v2_organization_scc_big_query_export" "default" {
name = "%{name}"
big_query_export_id = "%{big_query_export_id}"
organization = "%{org_id}"
Expand All @@ -133,7 +133,7 @@ resource "google_scc_v2_organization_scc_big_query_exports" "default" {
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_organization_scc_big_query_exports.default]
depends_on = [google_scc_v2_organization_scc_big_query_export.default]
}
`, context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package securitycenterv2_test

import (
"fmt"
"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 TestAccSecurityCenterV2OrganizationBigQueryExportsConfig_basic(t *testing.T) {
t.Parallel()

randomSuffix := acctest.RandString(t, 10)
dataset_id := "tf_test_" + randomSuffix
orgID := envvar.GetTestOrgFromEnv(t)

context := map[string]interface{}{
"org_id": orgID,
"random_suffix": randomSuffix,
"dataset_id": dataset_id,
"big_query_export_id": "tf-test-export-" + randomSuffix,
"name": fmt.Sprintf("organizations/%s/locations/global/bigQueryExports/%s",
orgID, "tf-test-export-"+randomSuffix),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
},
Steps: []resource.TestStep{
{
Config: testAccSecurityCenterV2OrganizationBigQueryExportsConfig_basic(context),
},
{
ResourceName: "google_scc_v2_organization_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
{
Config: testAccSecurityCenterV2OrganizationBigQueryExportsConfig_update(context),
},
{
ResourceName: "google_scc_v2_organization_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
},
})
}

func testAccSecurityCenterV2OrganizationBigQueryExportsConfig_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_bigquery_dataset" "default" {
dataset_id = "%{dataset_id}"
friendly_name = "test"
description = "This is a test description"
location = "US"
default_table_expiration_ms = 3600000
default_partition_expiration_ms = null
labels = {
env = "default"
}
lifecycle {
ignore_changes = [default_partition_expiration_ms]
}
}
resource "time_sleep" "wait_1_minute" {
depends_on = [google_bigquery_dataset.default]
create_duration = "3m"
}
resource "google_scc_v2_organization_scc_big_query_exports" "default" {
name = "%{name}"
big_query_export_id = "%{big_query_export_id}"
organization = "%{org_id}"
dataset = google_bigquery_dataset.default.id
location = "global"
description = "Cloud Security Command Center Findings Big Query Export Config"
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
depends_on = [time_sleep.wait_1_minute]
}
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_organization_scc_big_query_exports.default]
}
`, context)
}

func testAccSecurityCenterV2OrganizationBigQueryExportsConfig_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_bigquery_dataset" "default" {
dataset_id = "%{dataset_id}"
friendly_name = "test"
description = "This is a test description"
location = "US"
default_table_expiration_ms = 3600000
default_partition_expiration_ms = null
labels = {
env = "default"
}
lifecycle {
ignore_changes = [default_partition_expiration_ms]
}
}
resource "google_scc_v2_organization_scc_big_query_exports" "default" {
name = "%{name}"
big_query_export_id = "%{big_query_export_id}"
organization = "%{org_id}"
dataset = google_bigquery_dataset.default.id
location = "global"
description = "SCC Findings Big Query Export Update"
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
}
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_organization_scc_big_query_exports.default]
}
`, context)
}
Loading

0 comments on commit 541c568

Please sign in to comment.