From 28afe7564c7347aef29204019b084c9d25785541 Mon Sep 17 00:00:00 2001 From: Zhenhua Li Date: Fri, 27 Dec 2024 09:02:20 -0800 Subject: [PATCH] test --- mmv1/products/chronicle/Watchlist.yaml | 127 ++++++++++++++++++ mmv1/products/chronicle/product.yaml | 22 +++ .../chronicle_watchlist_basic.tf.tmpl | 20 +++ .../components/inputs/services_beta.kt | 5 + .../components/inputs/services_ga.kt | 5 + .../resource_chronicle_watchlist_test.go.tmpl | 97 +++++++++++++ 6 files changed, 276 insertions(+) create mode 100644 mmv1/products/chronicle/Watchlist.yaml create mode 100644 mmv1/products/chronicle/product.yaml create mode 100644 mmv1/templates/terraform/examples/chronicle_watchlist_basic.tf.tmpl create mode 100644 mmv1/third_party/terraform/services/chronicle/resource_chronicle_watchlist_test.go.tmpl diff --git a/mmv1/products/chronicle/Watchlist.yaml b/mmv1/products/chronicle/Watchlist.yaml new file mode 100644 index 000000000000..bf25d71a9e45 --- /dev/null +++ b/mmv1/products/chronicle/Watchlist.yaml @@ -0,0 +1,127 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: Watchlist +description: A watchlist is a list of entities that allows for bulk operations over the included entities. +min_version: beta +references: + guides: + 'Google SecOps Guides': 'https://cloud.google.com/chronicle/docs/secops/secops-overview' + api: 'https://cloud.google.com/chronicle/docs/reference/rest/v1alpha/projects.locations.instances.watchlists' +base_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists +self_link: projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists/{{watchlist_id}} +create_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists?watchlistId={{watchlist_id}} +id_format: projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists/{{watchlist_id}} +import_format: + - projects/{{project}}/locations/{{location}}/instances/{{instance}}/watchlists/{{watchlist_id}} +update_verb: PATCH +update_mask: true + +examples: + - name: 'chronicle_watchlist_basic' + primary_resource_id: 'example' + min_version: 'beta' + vars: + name: watchlist-name + description: watchlist-description + test_env_vars: + chronicle_id: 'CHRONICLE_ID' + +parameters: + - name: location + type: String + description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122. + immutable: true + url_param_only: true + required: true + - name: instance + type: String + description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122. + immutable: true + url_param_only: true + required: true + - name: watchlistId + type: String + description: |- + Optional. The ID to use for the watchlist, + which will become the final component of the watchlist's resource name. + This value should be 4-63 characters, and valid characters + are /a-z-/. + immutable: true + url_param_only: true + required: true +properties: + - name: name + type: String + description: |- + Identifier. Resource name of the watchlist. + Format: + projects/{project}/locations/{location}/instances/{instance}/watchlists/{watchlist} + default_from_api: true + - name: multiplyingFactor + type: Double + description: |- + Optional. Weight applied to the risk score for entities + in this watchlist. + The default is 1.0 if it is not specified. + - name: createTime + type: String + description: Output only. Time the watchlist was created. + output: true + - name: updateTime + type: String + description: Output only. Time the watchlist was last updated. + output: true + - name: displayName + type: String + description: |- + Required. Display name of the watchlist. + Note that it must be at least one character and less than 63 characters + (https://google.aip.dev/148). + required: true + - name: description + type: String + description: Optional. Description of the watchlist. + - name: entityPopulationMechanism + type: NestedObject + description: Mechanism to populate entities in the watchlist. + required: true + properties: + - name: manual + type: NestedObject + description: Entities are added manually. + allow_empty_object: true + send_empty_value: true + properties: + [] # Meant to be an empty object with no properties. + - name: entityCount + type: NestedObject + description: Count of different types of entities in the watchlist. + output: true + properties: + - name: user + type: Integer + description: Output only. Count of user type entities in the watchlist. + output: true + - name: asset + type: Integer + description: Output only. Count of asset type entities in the watchlist. + output: true + - name: watchlistUserPreferences + type: NestedObject + description: A collection of user preferences for watchlist UI configuration. + properties: + - name: pinned + type: Boolean + description: Optional. Whether the watchlist is pinned on the dashboard. diff --git a/mmv1/products/chronicle/product.yaml b/mmv1/products/chronicle/product.yaml new file mode 100644 index 000000000000..872defe877b0 --- /dev/null +++ b/mmv1/products/chronicle/product.yaml @@ -0,0 +1,22 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: Chronicle +display_name: Chronicle +scopes: + - https://www.googleapis.com/auth/cloud-platform +versions: + - base_url: https://{{location}}-chronicle.googleapis.com/v1beta/ + name: beta +caibaseurl: "" diff --git a/mmv1/templates/terraform/examples/chronicle_watchlist_basic.tf.tmpl b/mmv1/templates/terraform/examples/chronicle_watchlist_basic.tf.tmpl new file mode 100644 index 000000000000..34186482211a --- /dev/null +++ b/mmv1/templates/terraform/examples/chronicle_watchlist_basic.tf.tmpl @@ -0,0 +1,20 @@ +provider "google-beta" { + user_project_override = true +} + +resource "google_chronicle_watchlist" "{{$.PrimaryResourceId}}" { + provider = "google-beta" + location = "us" + instance = "{{index $.TestEnvVars "chronicle_id"}}" + watchlist_id = "{{index $.Vars "name"}}" + description = "{{index $.Vars "description"}}" + display_name = "{{index $.Vars "name"}}" + entity_population_mechanism { + manual { + + } + } + watchlist_user_preferences { + pinned = true + } +} diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt index be44dcb96987..24abf96b5b4f 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt @@ -141,6 +141,11 @@ var ServicesListBeta = mapOf( "displayName" to "Certificatemanager", "path" to "./google-beta/services/certificatemanager" ), + "chronicle" to mapOf( + "name" to "chronicle", + "displayName" to "Chronicle", + "path" to "./google-beta/services/chronicle" + ), "cloudasset" to mapOf( "name" to "cloudasset", "displayName" to "Cloudasset", diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt index 817c79f96f11..2c7b8722ff74 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt @@ -141,6 +141,11 @@ var ServicesListGa = mapOf( "displayName" to "Certificatemanager", "path" to "./google/services/certificatemanager" ), + "chronicle" to mapOf( + "name" to "chronicle", + "displayName" to "Chronicle", + "path" to "./google-beta/services/chronicle" + ), "cloudasset" to mapOf( "name" to "cloudasset", "displayName" to "Cloudasset", diff --git a/mmv1/third_party/terraform/services/chronicle/resource_chronicle_watchlist_test.go.tmpl b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_watchlist_test.go.tmpl new file mode 100644 index 000000000000..4888b7dd9d32 --- /dev/null +++ b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_watchlist_test.go.tmpl @@ -0,0 +1,97 @@ +package chronicle_test + +{{- if ne $.TargetVersionName "ga" }} + +import ( + "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 TestAccChronicleWatchlist_chronicleWatchlistBasicExample_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "chronicle_id": envvar.GetTestChronicleInstanceIdFromEnv(t), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), + CheckDestroy: testAccCheckChronicleWatchlistDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccChronicleWatchlist_chronicleWatchlistBasicExample_basic(context), + }, + { + ResourceName: "google_chronicle_watchlist.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"instance", "location", "watchlist_id"}, + }, + { + Config: testAccChronicleWatchlist_chronicleWatchlistBasicExample_update(context), + }, + { + ResourceName: "google_chronicle_watchlist.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"instance", "location", "watchlist_id"}, + }, + }, + }) +} + +func testAccChronicleWatchlist_chronicleWatchlistBasicExample_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google-beta" { + user_project_override = true +} + +resource "google_chronicle_watchlist" "example" { + provider = "google-beta" + location = "us" + instance = "%{chronicle_id}" + watchlist_id = "tf-test-watchlist-name%{random_suffix}" + description = "tf-test-watchlist-description%{random_suffix}" + display_name = "tf-test-watchlist-name%{random_suffix}" + multiplying_factor = 1 + entity_population_mechanism { + manual { + + } + } +} +`, context) +} + +func testAccChronicleWatchlist_chronicleWatchlistBasicExample_update(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google-beta" { + user_project_override = true +} + +resource "google_chronicle_watchlist" "example" { + provider = "google-beta" + location = "us" + instance = "%{chronicle_id}" + watchlist_id = "tf-test-watchlist-name%{random_suffix}" + description = "tf-test-watchlist-updated-description%{random_suffix}" + display_name = "tf-test-updated-watchlist%{random_suffix}" + multiplying_factor = 2 + entity_population_mechanism { + manual { + + } + } + watchlist_user_preferences { + pinned = true + } +} +`, context) +} +{{- end }}