Skip to content

Commit d11254a

Browse files
vijaykanthmiyabchen
authored andcommitted
Add Resource V2 SCC Findings Export to BQ Project Config (GoogleCloudPlatform#11534)
1 parent e197b98 commit d11254a

File tree

3 files changed

+293
-0
lines changed

3 files changed

+293
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
--- !ruby/object:Api::Resource
15+
name: 'ProjectSccBigQueryExports'
16+
base_url: projects/{{project}}/locations/{{location}}/bigQueryExports
17+
self_link: projects/{{project}}/locations/{{location}}/bigQueryExports/{{big_query_export_id}}
18+
create_url: projects/{{project}}/locations/{{location}}/bigQueryExports?bigQueryExportId={{big_query_export_id}}
19+
update_verb: :PATCH
20+
update_mask: true
21+
import_format:
22+
- 'projects/{{project}}/locations/{{location}}/bigQueryExports/{{big_query_export_id}}'
23+
description: |
24+
A Cloud Security Command Center (Cloud SCC) Big Query Export Config.
25+
It represents exporting Security Command Center data, including assets, findings, and security marks
26+
using gcloud scc bqexports
27+
~> **Note:** In order to use Cloud SCC resources, your organization must be enrolled
28+
in [SCC Standard/Premium](https://cloud.google.com/security-command-center/docs/quickstart-security-command-center).
29+
Without doing so, you may run into errors during resource creation.
30+
references: !ruby/object:Api::Resource::ReferenceLinks
31+
guides:
32+
'Official Documentation': 'https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query'
33+
api: 'https://cloud.google.com/security-command-center/docs/reference/rest/v2/projects.locations.bigQueryExports'
34+
examples:
35+
- !ruby/object:Provider::Terraform::Examples
36+
name: 'scc_v2_project_big_query_export_config_basic'
37+
primary_resource_id: 'custom_big_query_export_config'
38+
external_providers: ["random", "time"]
39+
skip_test: true
40+
vars:
41+
big_query_export_id: 'my-export'
42+
dataset: 'my-dataset'
43+
dataset_id: 'my_dataset_id'
44+
name: 'my-export'
45+
test_env_vars:
46+
org_id: :ORG_ID
47+
project: :PROJECT_NAME
48+
ignore_read_extra:
49+
- 'project'
50+
51+
parameters:
52+
- !ruby/object:Api::Type::String
53+
name: bigQueryExportId
54+
required: true
55+
immutable: true
56+
url_param_only: true
57+
description: |
58+
This must be unique within the organization.
59+
- !ruby/object:Api::Type::String
60+
name: location
61+
immutable: true
62+
url_param_only: true
63+
default_value: global
64+
description: |
65+
location Id is provided by organization. If not provided, Use global as default.
66+
properties:
67+
- !ruby/object:Api::Type::String
68+
name: name
69+
output: true
70+
description: |
71+
The resource name of this export, in the format
72+
`projects/{{project}}/locations/{{location}}/bigQueryExports/{{big_query_export_id}}`.
73+
This field is provided in responses, and is ignored when provided in create requests.
74+
- !ruby/object:Api::Type::String
75+
name: description
76+
description: |
77+
The description of the notification config (max of 1024 characters).
78+
validation: !ruby/object:Provider::Terraform::Validation
79+
function: 'validation.StringLenBetween(0, 1024)'
80+
- !ruby/object:Api::Type::String
81+
name: dataset
82+
description: |
83+
The dataset to write findings' updates to.
84+
Its format is "projects/[projectId]/datasets/[bigquery_dataset_id]".
85+
BigQuery Dataset unique ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_).
86+
- !ruby/object:Api::Type::String
87+
name: createTime
88+
output: true
89+
description: |
90+
The time at which the BigQuery export was created. This field is set by the server and will be ignored if provided on export on creation.
91+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
92+
Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
93+
- !ruby/object:Api::Type::String
94+
name: updateTime
95+
output: true
96+
description: |
97+
The most recent time at which the BigQuery export was updated. This field is set by the server and will be ignored if provided on export creation or update.
98+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
99+
Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
100+
- !ruby/object:Api::Type::String
101+
name: mostRecentEditor
102+
output: true
103+
description: |
104+
Email address of the user who last edited the BigQuery export.
105+
This field is set by the server and will be ignored if provided on export creation or update.
106+
- !ruby/object:Api::Type::String
107+
name: principal
108+
output: true
109+
description: |
110+
The service account that needs permission to create table and upload data to the BigQuery dataset.
111+
- !ruby/object:Api::Type::String
112+
name: filter
113+
description: |
114+
Expression that defines the filter to apply across create/update
115+
events of findings. The
116+
expression is a list of zero or more restrictions combined via
117+
logical operators AND and OR. Parentheses are supported, and OR
118+
has higher precedence than AND.
119+
120+
Restrictions have the form <field> <operator> <value> and may have
121+
a - character in front of them to indicate negation. The fields
122+
map to those defined in the corresponding resource.
123+
124+
The supported operators are:
125+
126+
* = for all value types.
127+
* >, <, >=, <= for integer values.
128+
* :, meaning substring matching, for strings.
129+
130+
The supported value types are:
131+
132+
* string literals in quotes.
133+
* integer literals without quotes.
134+
* boolean literals true and false without quotes.
135+
136+
See
137+
[Filtering notifications](https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications)
138+
for information on how to write a filter.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "google_bigquery_dataset" "default" {
2+
dataset_id = "<%= ctx[:vars]['dataset_id'] %>"
3+
friendly_name = "test"
4+
description = "This is a test description"
5+
location = "US"
6+
default_table_expiration_ms = 3600000
7+
default_partition_expiration_ms = null
8+
9+
labels = {
10+
env = "default"
11+
}
12+
13+
lifecycle {
14+
ignore_changes = [default_partition_expiration_ms]
15+
}
16+
}
17+
18+
resource "google_scc_v2_project_scc_big_query_exports" "<%= ctx[:primary_resource_id] %>" {
19+
name = "<%= ctx[:vars]['name'] %>"
20+
big_query_export_id = "<%= ctx[:vars]['big_query_export_id'] %>"
21+
project = "<%= ctx[:test_env_vars]['project'] %>"
22+
dataset = google_bigquery_dataset.default.id
23+
location = "global"
24+
description = "Cloud Security Command Center Findings Big Query Export Config"
25+
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package securitycenterv2_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
func TestAccSecurityCenterV2ProjectBigQueryExportConfig_basic(t *testing.T) {
13+
t.Parallel()
14+
15+
randomSuffix := acctest.RandString(t, 10)
16+
dataset_id := "tf_test_" + randomSuffix
17+
orgID := envvar.GetTestOrgFromEnv(t)
18+
19+
context := map[string]interface{}{
20+
"org_id": orgID,
21+
"random_suffix": randomSuffix,
22+
"dataset_id": dataset_id,
23+
"big_query_export_id": "tf-test-export-" + randomSuffix,
24+
"name": fmt.Sprintf("projects/%s/locations/global/bigQueryExports/%s",
25+
envvar.GetTestProjectFromEnv(), "tf-test-export-"+randomSuffix),
26+
"project": envvar.GetTestProjectFromEnv(),
27+
}
28+
29+
acctest.VcrTest(t, resource.TestCase{
30+
PreCheck: func() { acctest.AccTestPreCheck(t) },
31+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
32+
ExternalProviders: map[string]resource.ExternalProvider{
33+
"random": {},
34+
"time": {},
35+
},
36+
Steps: []resource.TestStep{
37+
{
38+
Config: testAccSecurityCenterV2ProjectBigQueryExportConfig_basic(context),
39+
},
40+
{
41+
ResourceName: "google_scc_v2_project_scc_big_query_exports.default",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
ImportStateVerifyIgnore: []string{"update_time", "project"},
45+
},
46+
{
47+
Config: testAccSecurityCenterV2ProjectBigQueryExportConfig_update(context),
48+
},
49+
{
50+
ResourceName: "google_scc_v2_project_scc_big_query_exports.default",
51+
ImportState: true,
52+
ImportStateVerify: true,
53+
ImportStateVerifyIgnore: []string{"update_time", "project"},
54+
},
55+
},
56+
})
57+
}
58+
59+
func testAccSecurityCenterV2ProjectBigQueryExportConfig_basic(context map[string]interface{}) string {
60+
return acctest.Nprintf(`
61+
62+
resource "google_bigquery_dataset" "default" {
63+
dataset_id = "%{dataset_id}"
64+
friendly_name = "test"
65+
description = "This is a test description"
66+
location = "US"
67+
default_table_expiration_ms = 3600000
68+
default_partition_expiration_ms = null
69+
70+
labels = {
71+
env = "default"
72+
}
73+
74+
lifecycle {
75+
ignore_changes = [default_partition_expiration_ms]
76+
}
77+
}
78+
79+
resource "time_sleep" "wait_1_minute" {
80+
depends_on = [google_bigquery_dataset.default]
81+
create_duration = "3m"
82+
}
83+
84+
resource "google_scc_v2_project_scc_big_query_exports" "default" {
85+
big_query_export_id = "%{big_query_export_id}"
86+
project = "%{project}"
87+
dataset = google_bigquery_dataset.default.id
88+
location = "global"
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 testAccSecurityCenterV2ProjectBigQueryExportConfig_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_v2_project_scc_big_query_exports" "default" {
119+
big_query_export_id = "%{big_query_export_id}"
120+
project = "%{project}"
121+
dataset = google_bigquery_dataset.default.id
122+
location = "global"
123+
description = "SCC Findings Big Query Export Update"
124+
filter = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
125+
126+
}
127+
128+
`, context)
129+
}

0 commit comments

Comments
 (0)