Skip to content

Commit

Permalink
Add schema resource (GoogleCloudPlatform#11018)
Browse files Browse the repository at this point in the history
  • Loading branch information
jialei-chen authored and rainshen49 committed Aug 21, 2024
1 parent 62ef3ad commit 836a8ab
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
107 changes: 107 additions & 0 deletions mmv1/products/discoveryengine/Schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 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.

--- !ruby/object:Api::Resource
name: 'Schema'
description: |
Schema defines the structure and layout of a type of document data.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Provide a schema for your data store': 'https://cloud.google.com/generative-ai-app-builder/docs/provide-schema'
api: 'https://cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1/projects.locations.collections.dataStores.schemas'

immutable: true
base_url: 'projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas'
self_link: 'projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}'
create_url: 'projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas?schemaId={{schema_id}}'
delete_url: 'projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}'
import_format:
[
'projects/{{project}}/locations/{{location}}/collections/default_collection/dataStores/{{data_store_id}}/schemas/{{schema_id}}',
]

autogen_async: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: "name"
base_url: "{{op_id}}"
wait_ms: 1000
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 60
update_minutes: 60
delete_minutes: 60
result: !ruby/object:Api::OpAsync::Result
path: "response"
status: !ruby/object:Api::OpAsync::Status
path: "done"
complete: true
allowed:
- true
- false
error: !ruby/object:Api::OpAsync::Error
path: "error"
message: "message"

examples:
- !ruby/object:Provider::Terraform::Examples
name: "discoveryengine_schema_basic"
primary_resource_id: 'basic'
vars:
data_store_id: "data-store-id"
schema_id: "schema-id"
parameters:
- !ruby/object:Api::Type::String
name: 'location'
required: true
immutable: true
url_param_only: true
description: |
The geographic location where the data store should reside. The value can
only be one of "global", "us" and "eu".
- !ruby/object:Api::Type::String
name: 'dataStoreId'
required: true
immutable: true
url_param_only: true
description: |
The unique id of the data store.
- !ruby/object:Api::Type::String
name: 'schemaId'
required: true
immutable: true
url_param_only: true
description: |
The unique id of the schema.
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
The unique full resource name of the schema. Values are of the format
`projects/{project}/locations/{location}/collections/{collection_id}/dataStores/{data_store_id}/schemas/{schema_id}`.
This field must be a UTF-8 encoded string with a length limit of 1024
characters.
output: true
- !ruby/object:Api::Type::String
name: 'jsonSchema'
description: |
The JSON representation of the schema.
immutable: true
exactly_one_of:
- json_schema
custom_flatten: 'templates/terraform/custom_flatten/discoveryengine_schema_json_schema.go.erb'
state_func:
'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v);
return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.StringIsJSON'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%# The license inside this block applies to this file.
# 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.
-%>

func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
s, err := structure.NormalizeJsonString(v)
if err != nil {
log.Printf("[ERROR] failed to normalize JSON string: %v", err)
}
return s
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "google_discovery_engine_schema" "basic" {
location = google_discovery_engine_data_store.basic.location
data_store_id = google_discovery_engine_data_store.basic.data_store_id
schema_id = "<%= ctx[:vars]['schema_id'] %>"
json_schema = "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"datetime_detection\":true,\"type\":\"object\",\"geolocation_detection\":true}"
}

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
skip_default_schema_creation = true
}

0 comments on commit 836a8ab

Please sign in to comment.