Skip to content

Commit

Permalink
Upgrade to the latest SDK and update schema customization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Mar 11, 2024
1 parent 0a1b6b9 commit d140380
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions vectorsearch/resource_vector_search_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
})
Expand All @@ -38,32 +29,23 @@ 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 {
w, err := c.WorkspaceClient()
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()
Expand Down

0 comments on commit d140380

Please sign in to comment.