Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Resource V2 SCC Findings Export to BQ Project Config #19311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11534.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_scc_v2_project_scc_big_query_exports`
```
5 changes: 3 additions & 2 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 450
// Generated resources: 451
// Generated IAM resources: 258
// Total generated resources: 708
// Total generated resources: 709
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -1057,6 +1057,7 @@ var generatedResources = map[string]*schema.Resource{
"google_scc_v2_organization_source_iam_policy": tpgiamresource.ResourceIamPolicy(securitycenterv2.SecurityCenterV2OrganizationSourceIamSchema, securitycenterv2.SecurityCenterV2OrganizationSourceIamUpdaterProducer, securitycenterv2.SecurityCenterV2OrganizationSourceIdParseFunc),
"google_scc_v2_project_mute_config": securitycenterv2.ResourceSecurityCenterV2ProjectMuteConfig(),
"google_scc_v2_project_notification_config": securitycenterv2.ResourceSecurityCenterV2ProjectNotificationConfig(),
"google_scc_v2_project_scc_big_query_exports": securitycenterv2.ResourceSecurityCenterV2ProjectSccBigQueryExports(),
"google_securityposture_posture": securityposture.ResourceSecurityposturePosture(),
"google_securityposture_posture_deployment": securityposture.ResourceSecurityposturePostureDeployment(),
"google_endpoints_service_iam_binding": tpgiamresource.ResourceIamBinding(servicemanagement.ServiceManagementServiceIamSchema, servicemanagement.ServiceManagementServiceIamUpdaterProducer, servicemanagement.ServiceManagementServiceIdParseFunc),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// 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/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccSecurityCenterV2ProjectBigQueryExportConfig_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("projects/%s/locations/global/bigQueryExports/%s",
envvar.GetTestProjectFromEnv(), "tf-test-export-"+randomSuffix),
"project": envvar.GetTestProjectFromEnv(),
}

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: testAccSecurityCenterV2ProjectBigQueryExportConfig_basic(context),
},
{
ResourceName: "google_scc_v2_project_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time", "project"},
},
{
Config: testAccSecurityCenterV2ProjectBigQueryExportConfig_update(context),
},
{
ResourceName: "google_scc_v2_project_scc_big_query_exports.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"update_time", "project"},
},
},
})
}

func testAccSecurityCenterV2ProjectBigQueryExportConfig_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_project_scc_big_query_exports" "default" {
big_query_export_id = "%{big_query_export_id}"
project = "%{project}"
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]
}

`, context)
}

func testAccSecurityCenterV2ProjectBigQueryExportConfig_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_project_scc_big_query_exports" "default" {
big_query_export_id = "%{big_query_export_id}"
project = "%{project}"
dataset = google_bigquery_dataset.default.id
location = "global"
description = "SCC Findings Big Query Export Update"
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""

}

`, context)
}
Loading