Skip to content

Commit 2c5260b

Browse files
Add Resource v1 SCC Findings Export to BQ Organization Config (#11582) (#8172)
[upstream:6acfa01a1ef4a26eafddbf2d42bf9cee60a0b742] Signed-off-by: Modular Magician <[email protected]>
1 parent 027e836 commit 2c5260b

6 files changed

+917
-2
lines changed

.changelog/11582.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_scc_organization_scc_big_query_export`
3+
```

google-beta/provider/provider_mmv1_resources.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
481481
}
482482

483483
// Resources
484-
// Generated resources: 517
484+
// Generated resources: 518
485485
// Generated IAM resources: 291
486-
// Total generated resources: 808
486+
// Total generated resources: 809
487487
var generatedResources = map[string]*schema.Resource{
488488
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
489489
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -1171,6 +1171,7 @@ var generatedResources = map[string]*schema.Resource{
11711171
"google_scc_mute_config": securitycenter.ResourceSecurityCenterMuteConfig(),
11721172
"google_scc_notification_config": securitycenter.ResourceSecurityCenterNotificationConfig(),
11731173
"google_scc_organization_custom_module": securitycenter.ResourceSecurityCenterOrganizationCustomModule(),
1174+
"google_scc_organization_scc_big_query_export": securitycenter.ResourceSecurityCenterOrganizationSccBigQueryExport(),
11741175
"google_scc_project_custom_module": securitycenter.ResourceSecurityCenterProjectCustomModule(),
11751176
"google_scc_project_notification_config": securitycenter.ResourceSecurityCenterProjectNotificationConfig(),
11761177
"google_scc_source": securitycenter.ResourceSecurityCenterSource(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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

Comments
 (0)