From d1403808603848201f835363907b321b14a0e459 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Mon, 11 Mar 2024 16:01:04 +0100 Subject: [PATCH] Upgrade to the latest SDK and update schema customization --- vectorsearch/resource_vector_search_index.go | 34 +++++--------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/vectorsearch/resource_vector_search_index.go b/vectorsearch/resource_vector_search_index.go index 549a585467..5271e4b228 100644 --- a/vectorsearch/resource_vector_search_index.go +++ b/vectorsearch/resource_vector_search_index.go @@ -2,7 +2,6 @@ package vectorsearch import ( "context" - "fmt" "github.com/databricks/terraform-provider-databricks/common" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -14,18 +13,10 @@ func ResourceVectorSearchIndex() common.Resource { s := common.StructToSchema( vectorsearch.CreateVectorIndexRequest{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { - common.CustomizeSchemaPath(s, "name").SetRequired().SetForceNew() - common.CustomizeSchemaPath(s, "primary_key").SetRequired().SetForceNew() - common.CustomizeSchemaPath(s, "index_type").SetRequired().SetForceNew() - - // common.CustomizeSchemaPath(s, "status").SetReadOnly() - // common.CustomizeSchemaPath(s, "creator").SetReadOnly() - - // common.CustomizeSchemaPath(s, "delta_sync_index_spec", "pipeline_id").SetReadOnly() - // // common.MustSchemaPath(s, "delta_sync_vector_index_spec", "embedding_vector_columns").MinItems = 1 - - // s["delta_sync_index_spec"].ExactlyOneOf = []string{"delta_sync_index_spec", "direct_access_index_spec"} - // s["direct_access_index_spec"].ExactlyOneOf = []string{"delta_sync_index_spec", "direct_access_index_spec"} + common.MustSchemaPath(s, "delta_sync_index_spec", "embedding_vector_columns").MinItems = 1 + exof := []string{"delta_sync_index_spec", "direct_access_index_spec"} + s["delta_sync_index_spec"].ExactlyOneOf = exof + s["direct_access_index_spec"].ExactlyOneOf = exof return s }) @@ -38,14 +29,11 @@ func ResourceVectorSearchIndex() common.Resource { } var req vectorsearch.CreateVectorIndexRequest common.DataToStructPointer(d, s, &req) - index, err := w.VectorSearchIndexes.CreateIndex(ctx, req) + _, err = w.VectorSearchIndexes.CreateIndex(ctx, req) if err != nil { return err } - if index.VectorIndex == nil { - return fmt.Errorf("vector index information is nil") - } - d.SetId(index.VectorIndex.Name) + d.SetId(req.Name) return nil }, Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { @@ -53,17 +41,11 @@ func ResourceVectorSearchIndex() common.Resource { if err != nil { return err } - index, err := w.VectorSearchIndexes.GetIndex(ctx, vectorsearch.GetIndexRequest{ - IndexName: d.Id(), - }) + index, err := w.VectorSearchIndexes.GetIndexByIndexName(ctx, d.Id()) if err != nil { return err } - err = common.StructToData(*index, s, d) - if err != nil { - return err - } - return nil + return common.StructToData(*index, s, d) }, Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { w, err := c.WorkspaceClient()