Skip to content

Commit

Permalink
Add Resource v1 SCC Findings Export to BQ Folder Config (#11587) (#8183)
Browse files Browse the repository at this point in the history
[upstream:6d67e349fe1f372cb7cb1bc1f720f858dab78187]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 13, 2024
1 parent 750b702 commit da8f625
Show file tree
Hide file tree
Showing 6 changed files with 929 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/11587.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_scc_folder_scc_big_query_export`
```
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 @@ -481,9 +481,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 523
// Generated resources: 524
// Generated IAM resources: 291
// Total generated resources: 814
// Total generated resources: 815
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -1171,6 +1171,7 @@ var generatedResources = map[string]*schema.Resource{
"google_scc_event_threat_detection_custom_module": securitycenter.ResourceSecurityCenterEventThreatDetectionCustomModule(),
"google_scc_folder_custom_module": securitycenter.ResourceSecurityCenterFolderCustomModule(),
"google_scc_folder_notification_config": securitycenter.ResourceSecurityCenterFolderNotificationConfig(),
"google_scc_folder_scc_big_query_export": securitycenter.ResourceSecurityCenterFolderSccBigQueryExport(),
"google_scc_mute_config": securitycenter.ResourceSecurityCenterMuteConfig(),
"google_scc_notification_config": securitycenter.ResourceSecurityCenterNotificationConfig(),
"google_scc_organization_custom_module": securitycenter.ResourceSecurityCenterOrganizationCustomModule(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// 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-plugin-testing/plancheck"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
)

func TestAccSecurityCenterFolderBigQueryExportConfig_update(t *testing.T) {
t.Parallel()

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

context := map[string]interface{}{
"org_id": orgID,
"random_suffix": randomSuffix,
"dataset_id": dataset_id,
"dataset_id2": dataset_id2,
"big_query_export_id": "tf-test-export-" + randomSuffix,
"folder_name": "tf-test-folder-name-" + randomSuffix,
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
Steps: []resource.TestStep{
{
Config: testAccSecurityCenterFolderBigQueryExportConfig_basic(context),
},
{
ResourceName: "google_scc_folder_scc_big_query_export.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
{
Config: testAccSecurityCenterFolderBigQueryExportConfig_update(context),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_scc_folder_scc_big_query_export.default", plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: "google_scc_folder_scc_big_query_export.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
},
})
}

func testAccSecurityCenterFolderBigQueryExportConfig_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_folder" "folder" {
parent = "organizations/%{org_id}"
display_name = "%{folder_name}"
deletion_protection = false
}
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_folder_scc_big_query_export" "default" {
big_query_export_id = "%{big_query_export_id}"
folder = google_folder.folder.folder_id
dataset = google_bigquery_dataset.default.id
description = "Cloud Security Command Center Findings Big Query Export Config"
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
depends_on = [time_sleep.wait_1_minute]
}
`, context)
}

func testAccSecurityCenterFolderBigQueryExportConfig_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_folder" "folder" {
parent = "organizations/%{org_id}"
display_name = "%{folder_name}"
deletion_protection = false
}
resource "google_bigquery_dataset" "default" {
dataset_id = "%{dataset_id2}"
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_folder_scc_big_query_export" "default" {
big_query_export_id = "%{big_query_export_id}"
folder = google_folder.folder.folder_id
dataset = google_bigquery_dataset.default.id
description = "SCC Findings Big Query Export Update"
filter = ""
}
`, context)
}
Loading

0 comments on commit da8f625

Please sign in to comment.