Skip to content

Commit

Permalink
Search Engine TF Provider (#9822)
Browse files Browse the repository at this point in the history
* Search Engine TF Provider

* Discovery Engine Search Engine

* Formatted Test File

* Updated Test File

* Added Examples to SearchEngine Config and added DS to basic test example

* Update mmv1/products/discoveryengine/SearchEngine.yaml

Co-authored-by: Ray <[email protected]>

* Updated SearchEngine.yaml file

* Updated SearchEngine.yaml

* Updated Search TF Files as per PR Review

* Updated files as per PR Review

* Set searchEngineConfig as required field in SearchEngine.yaml

* Removed default_from_api from SearchEngineConfig

* Added Changes as per PR review

---------

Co-authored-by: Ray <[email protected]>
  • Loading branch information
Pratster95 and 5fff authored Jan 31, 2024
1 parent a0178b8 commit 69eb35b
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 0 deletions.
151 changes: 151 additions & 0 deletions mmv1/products/discoveryengine/SearchEngine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright 2023 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.

--- !ruby/object:Api::Resource
name: 'SearchEngine'
description: |
Vertex AI Search and Conversation can be used to create a search engine or a chat application by connecting it with a datastore
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Create a Search Engine': 'https://cloud.google.com/generative-ai-app-builder/docs/create-engine-es'
api: 'https://cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1/projects.locations.collections.engines'

base_url: 'projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/engines/{{engine_id}}'
self_link: 'projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/engines/{{engine_id}}'
create_url: 'projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/engines?engineId={{engine_id}}'
delete_url: 'projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/engines/{{engine_id}}'

update_verb: :PATCH
update_mask: true

autogen_async: true

async: !ruby/object:Api::OpAsync
actions: ['create', 'delete']
operation: !ruby/object:Api::OpAsync::Operation
base_url: '{{op_id}}'
result: !ruby/object:Api::OpAsync::Result
resource_inside_response: true

import_format:
[
'projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/engines/{{engine_id}}',
]
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/discovery_engine_search_engine_hardcode_solution_type.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: "discoveryengine_searchengine_basic"
primary_resource_id: 'basic'
vars:
engine_id: "example-engine-id"
data_store_id: "example-datastore-id"

parameters:
- !ruby/object:Api::Type::String
name: 'engineId'
description: |
Unique ID to use for Search Engine App.
required: true
immutable: true
url_param_only: true
- !ruby/object:Api::Type::String
name: 'collectionId'
description: |
The collection ID.
required: true
immutable: true
url_param_only: true
- !ruby/object:Api::Type::String
name: 'location'
description: |
Location.
required: true
immutable: true
url_param_only: true

properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
The unique full resource name of the search engine. Values are of the format
`projects/{project}/locations/{location}/collections/{collection_id}/engines/{engine_id}`.
This field must be a UTF-8 encoded string with a length limit of 1024
characters.
output: true
- !ruby/object:Api::Type::Enum
name: 'industryVertical'
description: |
The industry vertical that the engine registers. The restriction of the Engine industry vertical is based on DataStore: If unspecified, default to GENERIC. Vertical on Engine has to match vertical of the DataStore liniked to the engine.
immutable: true
values:
- :GENERIC
- :MEDIA
default_value: :GENERIC
- !ruby/object:Api::Type::String
name: 'displayName'
description: |
Required. The display name of the engine. Should be human readable. UTF-8 encoded string with limit of 1024 characters.
required: true
- !ruby/object:Api::Type::Array
name: 'dataStoreIds'
description: |
The data stores associated with this engine. For SOLUTION_TYPE_SEARCH type of engines, they can only associate with at most one data store.
required: true
immutable: true
item_type: Api::Type::String
- !ruby/object:Api::Type::Time
name: 'createTime'
description: |
Timestamp the Engine was created at.
output: true
- !ruby/object:Api::Type::Time
name: 'updateTime'
description: |
Timestamp the Engine was last updated.
output: true
- !ruby/object:Api::Type::NestedObject
name: 'searchEngineConfig'
description: |
Configurations for a Search Engine.
required: true
properties:
- !ruby/object:Api::Type::Enum
name: 'searchTier'
description: |
The search feature tier of this engine. Defaults to SearchTier.SEARCH_TIER_STANDARD if not specified.
values:
- :SEARCH_TIER_STANDARD
- :SEARCH_TIER_ENTERPRISE
default_value: :SEARCH_TIER_STANDARD
- !ruby/object:Api::Type::Array
name: 'searchAddOns'
description: |
The add-on that this search engine enables.
item_type: !ruby/object:Api::Type::Enum
name: 'searchAddOn'
description: |
The add-on that this search engine enables.
values:
- :SEARCH_ADD_ON_LLM
- !ruby/object:Api::Type::NestedObject
name: 'commonConfig'
description: |
Common config spec that specifies the metadata of the engine.
immutable: true
properties:
- !ruby/object:Api::Type::String
name: 'companyName'
description: |
The name of the company, business or entity that is associated with the engine. Setting this may help improve LLM related features.cd
immutable: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// hard code solutionType to "SOLUTION_TYPE_SEARCH" for search engine resource
obj["solutionType"] = "SOLUTION_TYPE_SEARCH"
return obj, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "google_discovery_engine_data_store" "basic" {
location = "global"
data_store_id = "<%= ctx[:vars]['data_store_id'] %>"
display_name = "tf-test-structured-datastore"
industry_vertical = "GENERIC"
content_config = "NO_CONTENT"
solution_types = ["SOLUTION_TYPE_SEARCH"]
create_advanced_site_search = false
}
resource "google_discovery_engine_search_engine" "basic" {
engine_id = "<%= ctx[:vars]['engine_id'] %>"
collection_id = "default_collection"
location = google_discovery_engine_data_store.basic.location
display_name = "Example Display Name"
data_store_ids = [google_discovery_engine_data_store.basic.data_store_id]
search_engine_config {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package discoveryengine_test

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"testing"
)

func TestAccDiscoveryEngineSearchEngine_discoveryengineSearchengineBasicExample_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() {
acctest.AccTestPreCheck(t)
},
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckDiscoveryEngineSearchEngineDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDiscoveryEngineSearchEngine_discoveryengineSearchengineBasicExample_basic(context),
},
{
ResourceName: "google_discovery_engine_search_engine.basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"engine_id", "collection_id", "location"},
},
{
Config: testAccDiscoveryEngineSearchEngine_discoveryengineSearchengineBasicExample_update(context),
},
{
ResourceName: "google_discovery_engine_search_engine.basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"engine_id", "collection_id", "location"},
},
},
})
}

func testAccDiscoveryEngineSearchEngine_discoveryengineSearchengineBasicExample_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_discovery_engine_data_store" "basic" {
location = "global"
data_store_id = "tf-test-example-datastore%{random_suffix}"
display_name = "tf-test-structured-datastore"
industry_vertical = "GENERIC"
content_config = "NO_CONTENT"
solution_types = ["SOLUTION_TYPE_SEARCH"]
create_advanced_site_search = false
}
resource "google_discovery_engine_search_engine" "basic" {
engine_id = "tf-test-example-engine-id%{random_suffix}"
collection_id = "default_collection"
location = google_discovery_engine_data_store.basic.location
display_name = "Example Display Name"
data_store_ids = [google_discovery_engine_data_store.basic.data_store_id]
industry_vertical = google_discovery_engine_data_store.basic.industry_vertical
common_config {
company_name = "Example Company Name"
}
search_engine_config {
search_tier = "SEARCH_TIER_ENTERPRISE"
search_add_ons = ["SEARCH_ADD_ON_LLM"]
}
}
`, context)
}

func testAccDiscoveryEngineSearchEngine_discoveryengineSearchengineBasicExample_update(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_discovery_engine_data_store" "basic" {
location = "global"
data_store_id = "tf-test-example-datastore%{random_suffix}"
display_name = "tf-test-structured-datastore"
industry_vertical = "GENERIC"
content_config = "NO_CONTENT"
solution_types = ["SOLUTION_TYPE_SEARCH"]
create_advanced_site_search = false
}
resource "google_discovery_engine_search_engine" "basic" {
engine_id = "tf-test-example-engine-id%{random_suffix}"
collection_id = "default_collection"
location = google_discovery_engine_data_store.basic.location
display_name = "Updated Example Display Name"
data_store_ids = [google_discovery_engine_data_store.basic.data_store_id]
industry_vertical = google_discovery_engine_data_store.basic.industry_vertical
common_config {
company_name = "Updated Example Company Name"
}
search_engine_config {
search_tier = "SEARCH_TIER_STANDARD"
search_add_ons = ["SEARCH_ADD_ON_LLM"]
}
}
`, context)
}

0 comments on commit 69eb35b

Please sign in to comment.