Skip to content

Commit

Permalink
Add Resource V2 SCC Findings Export to Big Query Folder Config (#1151…
Browse files Browse the repository at this point in the history
…7) (#8079)

[upstream:68282ea6e38b34150888bdff9bae1a27c73bb7f9]

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

// Resources
// Generated resources: 508
// Generated resources: 509
// Generated IAM resources: 288
// Total generated resources: 796
// Total generated resources: 797
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -1169,6 +1169,7 @@ var generatedResources = map[string]*schema.Resource{
"google_scc_management_project_security_health_analytics_custom_module": securitycentermanagement.ResourceSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule(),
"google_scc_v2_folder_mute_config": securitycenterv2.ResourceSecurityCenterV2FolderMuteConfig(),
"google_scc_v2_folder_notification_config": securitycenterv2.ResourceSecurityCenterV2FolderNotificationConfig(),
"google_scc_v2_folder_scc_big_query_exports": securitycenterv2.ResourceSecurityCenterV2FolderSccBigQueryExports(),
"google_scc_v2_organization_mute_config": securitycenterv2.ResourceSecurityCenterV2OrganizationMuteConfig(),
"google_scc_v2_organization_notification_config": securitycenterv2.ResourceSecurityCenterV2OrganizationNotificationConfig(),
"google_scc_v2_organization_scc_big_query_exports": securitycenterv2.ResourceSecurityCenterV2OrganizationSccBigQueryExports(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package securitycenterv2_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 TestAccSecurityCenterV2FolderBigQueryExportConfig_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,
"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{
"random": {},
"time": {},
},
Steps: []resource.TestStep{
{
Config: testAccSecurityCenterV2FolderBigQueryExportConfig_basic(context),
},
{
ResourceName: "google_scc_v2_folder_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
{
Config: testAccSecurityCenterV2FolderBigQueryExportConfig_update(context),
},
{
ResourceName: "google_scc_v2_folder_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time"},
},
},
})
}

func testAccSecurityCenterV2FolderBigQueryExportConfig_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_v2_folder_scc_big_query_exports" "default" {
big_query_export_id = "%{big_query_export_id}"
folder = google_folder.folder.folder_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\""
lifecycle {
ignore_changes = [name]
}
depends_on = [time_sleep.wait_1_minute]
}
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_folder_scc_big_query_exports.default]
}
`, context)
}

func testAccSecurityCenterV2FolderBigQueryExportConfig_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_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_folder_scc_big_query_exports" "default" {
big_query_export_id = "%{big_query_export_id}"
folder = google_folder.folder.folder_id
dataset = google_bigquery_dataset.default.id
location = "global"
description = "SCC Findings Big Query Export Update"
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
lifecycle {
ignore_changes = [name]
}
}
resource "time_sleep" "wait_for_cleanup" {
create_duration = "3m"
depends_on = [google_scc_v2_folder_scc_big_query_exports.default]
}
`, context)
}
Loading

0 comments on commit 06cab40

Please sign in to comment.