From 6b37520dcb36c237b5bbf5ae22c62f33c36640ab Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Thu, 9 Jan 2025 07:51:22 +0000 Subject: [PATCH 1/3] Add google_chronicle_reference_list resource to chronicle --- mmv1/products/chronicle/ReferenceList.yaml | 144 ++++++++++++++++++ .../chronicle_referencelist_basic.tf.tmpl | 11 ++ ...urce_chronicle_reference_list_test.go.tmpl | 79 ++++++++++ 3 files changed, 234 insertions(+) create mode 100644 mmv1/products/chronicle/ReferenceList.yaml create mode 100644 mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl create mode 100644 mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl diff --git a/mmv1/products/chronicle/ReferenceList.yaml b/mmv1/products/chronicle/ReferenceList.yaml new file mode 100644 index 000000000000..e15e6091354b --- /dev/null +++ b/mmv1/products/chronicle/ReferenceList.yaml @@ -0,0 +1,144 @@ +# 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: ReferenceList +description: Reference lists are user-defined lists of values which users can use in multiple Rules. +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.referenceLists' +base_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists +self_link: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} +create_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists?referenceListId={{reference_list_id}} +id_format: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} +import_format: +- projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} +update_verb: PATCH +update_mask: true +exclude_delete: true + +examples: +- name: 'chronicle_referencelist_basic' + primary_resource_id: 'example' + min_version: 'beta' + vars: + reference_list_id: reference_list_id + description: referencelist-description + reference_list_entry_value: "referencelist-entry-value" + test_env_vars: + chronicle_id: 'CHRONICLE_ID' + +parameters: +- name: location + type: String + description: The location of the resource. This is the geographical region where the Chronicle instance resides, such as "us" or "europe-west2". + immutable: true + url_param_only: true + required: true +- name: instance + type: String + description: The unique identifier for the Chronicle instance, which is the same as the customer ID. + immutable: true + url_param_only: true + required: true +- name: referenceListId + type: String + description: |- + Required. The ID to use for the reference list. This is also the display name for + the reference list. It must satisfy the following requirements: + - Starts with letter. + - Contains only letters, numbers and underscore. + - Has length < 256. + - Must be unique. + immutable: true + url_param_only: true + required: true +properties: +- name: name + type: String + description: |- + Output only. The resource name of the reference list. + Format: + projects/{project}/locations/{location}/instances/{instance}/referenceLists/{reference_list} + output: true +- name: description + type: String + description: Required. A user-provided description of the reference list. + required: true +- name: entries + type: Array + description: |- + Required. The entries of the reference list. + When listed, they are returned in the order that was specified at creation + or update. The combined size of the values of the reference list may not + exceed 6MB. + This is returned only when the view is REFERENCE_LIST_VIEW_FULL. + required: true + item_type: + type: NestedObject + properties: + - name: value + type: String + description: Required. The value of the entry. Maximum length is 512 characters. + required: true +- name: scopeInfo + type: NestedObject + output: true + description: ScopeInfo specifies the scope info of the reference list. + properties: + - name: referenceListScope + type: NestedObject + description: ReferenceListScope specifies the list of scope names of the reference list. + required: true + properties: + - name: scopeNames + type: Array + description: |- + Optional. The list of scope names of the reference list. The scope names should be + full resource names and should be of the format: + "projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}". + item_type: + type: String +- name: displayName + type: String + description: Output only. The unique display name of the reference list. + output: true +- name: revisionCreateTime + type: String + description: Output only. The timestamp when the reference list was last updated. + output: true +- name: rules + type: Array + description: |- + Output only. The resource names for the associated self-authored Rules that use this + reference list. + This is returned only when the view is REFERENCE_LIST_VIEW_FULL. + output: true + item_type: + type: String +- name: syntaxType + type: String + description: |2- + + Possible values: + REFERENCE_LIST_SYNTAX_TYPE_UNSPECIFIED + REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING + REFERENCE_LIST_SYNTAX_TYPE_REGEX + REFERENCE_LIST_SYNTAX_TYPE_CIDR + required: true +- name: ruleAssociationsCount + type: Integer + description: Output only. The count of self-authored rules using the reference list. + output: true diff --git a/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl b/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl new file mode 100644 index 000000000000..bae5b08596d7 --- /dev/null +++ b/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl @@ -0,0 +1,11 @@ +resource "google_chronicle_reference_list" "{{$.PrimaryResourceId}}" { + provider = "google-beta" + location = "us" + instance = "{{index $.TestEnvVars "chronicle_id"}}" + reference_list_id = "{{index $.Vars "reference_list_id"}}" + description = "{{index $.Vars "description"}}" + entries { + value = "{{index $.Vars "reference_list_entry_value"}}" + } + syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING" +} diff --git a/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl new file mode 100644 index 000000000000..63b1df2c2c88 --- /dev/null +++ b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl @@ -0,0 +1,79 @@ +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 TestAccChronicleReferenceList_chronicleReferencelistBasicExample_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), + Steps: []resource.TestStep{ + { + Config: testAccChronicleReferenceList_chronicleReferencelistBasicExample_basic(context), + }, + { + ResourceName: "google_chronicle_reference_list.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"instance", "location", "reference_list_id"}, + }, + { + Config: testAccChronicleReferenceList_chronicleReferencelistBasicExample_update(context), + }, + { + ResourceName: "google_chronicle_reference_list.example", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"instance", "location", "reference_list_id"}, + }, + }, + }) +} + +func testAccChronicleReferenceList_chronicleReferencelistBasicExample_basic(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_chronicle_reference_list" "example" { + provider = "google-beta" + location = "us" + instance = "%{chronicle_id}" + reference_list_id = "tf_test_reference_list_id%{random_suffix}" + description = "tf-test-referencelist-description%{random_suffix}" + entries { + value = "tf-test-referencelist-entry-value%{random_suffix}" + } + syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING" +} +`, context) +} + +func testAccChronicleReferenceList_chronicleReferencelistBasicExample_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_chronicle_reference_list" "example" { + provider = "google-beta" + location = "us" + instance = "%{chronicle_id}" + reference_list_id = "tf_test_reference_list_id%{random_suffix}" + description = "tf-test-referencelist-description-updated%{random_suffix}" + entries { + value = "tf-test-referencelist-entry-value-updated%{random_suffix}" + } + syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_REGEX" +} +`, context) +} +{{- end }} From 1cbb09b7132f43da23cb58219ee71af949d5a81b Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Thu, 9 Jan 2025 07:58:09 +0000 Subject: [PATCH 2/3] fixing lint issues --- mmv1/products/chronicle/ReferenceList.yaml | 210 ++++++++++----------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/mmv1/products/chronicle/ReferenceList.yaml b/mmv1/products/chronicle/ReferenceList.yaml index e15e6091354b..957d409f66e5 100644 --- a/mmv1/products/chronicle/ReferenceList.yaml +++ b/mmv1/products/chronicle/ReferenceList.yaml @@ -24,121 +24,121 @@ self_link: projects/{{project}}/locations/{{location}}/instances/{{instance}}/re create_url: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists?referenceListId={{reference_list_id}} id_format: projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} import_format: -- projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} + - projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}} update_verb: PATCH update_mask: true exclude_delete: true examples: -- name: 'chronicle_referencelist_basic' - primary_resource_id: 'example' - min_version: 'beta' - vars: - reference_list_id: reference_list_id - description: referencelist-description - reference_list_entry_value: "referencelist-entry-value" - test_env_vars: - chronicle_id: 'CHRONICLE_ID' + - name: 'chronicle_referencelist_basic' + primary_resource_id: 'example' + min_version: 'beta' + vars: + reference_list_id: reference_list_id + description: referencelist-description + reference_list_entry_value: "referencelist-entry-value" + test_env_vars: + chronicle_id: 'CHRONICLE_ID' parameters: -- name: location - type: String - description: The location of the resource. This is the geographical region where the Chronicle instance resides, such as "us" or "europe-west2". - immutable: true - url_param_only: true - required: true -- name: instance - type: String - description: The unique identifier for the Chronicle instance, which is the same as the customer ID. - immutable: true - url_param_only: true - required: true -- name: referenceListId - type: String - description: |- - Required. The ID to use for the reference list. This is also the display name for - the reference list. It must satisfy the following requirements: - - Starts with letter. - - Contains only letters, numbers and underscore. - - Has length < 256. - - Must be unique. - immutable: true - url_param_only: true - required: true + - name: location + type: String + description: The location of the resource. This is the geographical region where the Chronicle instance resides, such as "us" or "europe-west2". + immutable: true + url_param_only: true + required: true + - name: instance + type: String + description: The unique identifier for the Chronicle instance, which is the same as the customer ID. + immutable: true + url_param_only: true + required: true + - name: referenceListId + type: String + description: |- + Required. The ID to use for the reference list. This is also the display name for + the reference list. It must satisfy the following requirements: + - Starts with letter. + - Contains only letters, numbers and underscore. + - Has length < 256. + - Must be unique. + immutable: true + url_param_only: true + required: true properties: -- name: name - type: String - description: |- - Output only. The resource name of the reference list. - Format: - projects/{project}/locations/{location}/instances/{instance}/referenceLists/{reference_list} - output: true -- name: description - type: String - description: Required. A user-provided description of the reference list. - required: true -- name: entries - type: Array - description: |- - Required. The entries of the reference list. - When listed, they are returned in the order that was specified at creation - or update. The combined size of the values of the reference list may not - exceed 6MB. - This is returned only when the view is REFERENCE_LIST_VIEW_FULL. - required: true - item_type: + - name: name + type: String + description: |- + Output only. The resource name of the reference list. + Format: + projects/{project}/locations/{location}/instances/{instance}/referenceLists/{reference_list} + output: true + - name: description + type: String + description: Required. A user-provided description of the reference list. + required: true + - name: entries + type: Array + description: |- + Required. The entries of the reference list. + When listed, they are returned in the order that was specified at creation + or update. The combined size of the values of the reference list may not + exceed 6MB. + This is returned only when the view is REFERENCE_LIST_VIEW_FULL. + required: true + item_type: + type: NestedObject + properties: + - name: value + type: String + description: Required. The value of the entry. Maximum length is 512 characters. + required: true + - name: scopeInfo type: NestedObject + output: true + description: ScopeInfo specifies the scope info of the reference list. properties: - - name: value + - name: referenceListScope + type: NestedObject + description: ReferenceListScope specifies the list of scope names of the reference list. + required: true + properties: + - name: scopeNames + type: Array + description: |- + Optional. The list of scope names of the reference list. The scope names should be + full resource names and should be of the format: + "projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}". + item_type: + type: String + - name: displayName + type: String + description: Output only. The unique display name of the reference list. + output: true + - name: revisionCreateTime + type: String + description: Output only. The timestamp when the reference list was last updated. + output: true + - name: rules + type: Array + description: |- + Output only. The resource names for the associated self-authored Rules that use this + reference list. + This is returned only when the view is REFERENCE_LIST_VIEW_FULL. + output: true + item_type: type: String - description: Required. The value of the entry. Maximum length is 512 characters. - required: true -- name: scopeInfo - type: NestedObject - output: true - description: ScopeInfo specifies the scope info of the reference list. - properties: - - name: referenceListScope - type: NestedObject - description: ReferenceListScope specifies the list of scope names of the reference list. - required: true - properties: - - name: scopeNames - type: Array - description: |- - Optional. The list of scope names of the reference list. The scope names should be - full resource names and should be of the format: - "projects/{project}/locations/{location}/instances/{instance}/dataAccessScopes/{scope_name}". - item_type: - type: String -- name: displayName - type: String - description: Output only. The unique display name of the reference list. - output: true -- name: revisionCreateTime - type: String - description: Output only. The timestamp when the reference list was last updated. - output: true -- name: rules - type: Array - description: |- - Output only. The resource names for the associated self-authored Rules that use this - reference list. - This is returned only when the view is REFERENCE_LIST_VIEW_FULL. - output: true - item_type: + - name: syntaxType type: String -- name: syntaxType - type: String - description: |2- + description: |2- - Possible values: - REFERENCE_LIST_SYNTAX_TYPE_UNSPECIFIED - REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING - REFERENCE_LIST_SYNTAX_TYPE_REGEX - REFERENCE_LIST_SYNTAX_TYPE_CIDR - required: true -- name: ruleAssociationsCount - type: Integer - description: Output only. The count of self-authored rules using the reference list. - output: true + Possible values: + REFERENCE_LIST_SYNTAX_TYPE_UNSPECIFIED + REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING + REFERENCE_LIST_SYNTAX_TYPE_REGEX + REFERENCE_LIST_SYNTAX_TYPE_CIDR + required: true + - name: ruleAssociationsCount + type: Integer + description: Output only. The count of self-authored rules using the reference list. + output: true From 265165b322b3540cc0f286c0ea83e2f46adf858e Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Fri, 10 Jan 2025 10:58:09 +0000 Subject: [PATCH 3/3] Adding changes based on review comments --- mmv1/products/chronicle/ReferenceList.yaml | 5 +---- .../examples/chronicle_referencelist_basic.tf.tmpl | 4 ++-- .../resource_chronicle_reference_list_test.go.tmpl | 8 ++++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mmv1/products/chronicle/ReferenceList.yaml b/mmv1/products/chronicle/ReferenceList.yaml index 957d409f66e5..bc79d1796945 100644 --- a/mmv1/products/chronicle/ReferenceList.yaml +++ b/mmv1/products/chronicle/ReferenceList.yaml @@ -1,4 +1,4 @@ -# Copyright 2024 Google Inc. +# Copyright 2025 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 @@ -35,8 +35,6 @@ examples: min_version: 'beta' vars: reference_list_id: reference_list_id - description: referencelist-description - reference_list_entry_value: "referencelist-entry-value" test_env_vars: chronicle_id: 'CHRONICLE_ID' @@ -133,7 +131,6 @@ properties: description: |2- Possible values: - REFERENCE_LIST_SYNTAX_TYPE_UNSPECIFIED REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING REFERENCE_LIST_SYNTAX_TYPE_REGEX REFERENCE_LIST_SYNTAX_TYPE_CIDR diff --git a/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl b/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl index bae5b08596d7..5899e5a34ca5 100644 --- a/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl +++ b/mmv1/templates/terraform/examples/chronicle_referencelist_basic.tf.tmpl @@ -3,9 +3,9 @@ resource "google_chronicle_reference_list" "{{$.PrimaryResourceId}}" { location = "us" instance = "{{index $.TestEnvVars "chronicle_id"}}" reference_list_id = "{{index $.Vars "reference_list_id"}}" - description = "{{index $.Vars "description"}}" + description = "referencelist-description" entries { - value = "{{index $.Vars "reference_list_entry_value"}}" + value = "referencelist-entry-value" } syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING" } diff --git a/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl index 63b1df2c2c88..c3896d61594e 100644 --- a/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl +++ b/mmv1/third_party/terraform/services/chronicle/resource_chronicle_reference_list_test.go.tmpl @@ -52,9 +52,9 @@ resource "google_chronicle_reference_list" "example" { location = "us" instance = "%{chronicle_id}" reference_list_id = "tf_test_reference_list_id%{random_suffix}" - description = "tf-test-referencelist-description%{random_suffix}" + description = "referencelist-description" entries { - value = "tf-test-referencelist-entry-value%{random_suffix}" + value = "referencelist-entry-value" } syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_PLAIN_TEXT_STRING" } @@ -68,9 +68,9 @@ resource "google_chronicle_reference_list" "example" { location = "us" instance = "%{chronicle_id}" reference_list_id = "tf_test_reference_list_id%{random_suffix}" - description = "tf-test-referencelist-description-updated%{random_suffix}" + description = "referencelist-description-updated" entries { - value = "tf-test-referencelist-entry-value-updated%{random_suffix}" + value = "referencelist-entry-value-updated" } syntax_type = "REFERENCE_LIST_SYNTAX_TYPE_REGEX" }