From ead1bbf5cfd0020918acd16fd99c77ee6c28c91f Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Wed, 31 Jan 2024 17:46:05 +0100 Subject: [PATCH 01/14] WIP: Add support for Vector Search Endpoints Unit & integration tests needs to be added... --- docs/resources/vector_search_endpoint.md | 46 ++++++++++ provider/provider.go | 2 + .../resource_vector_search_endpoint.go | 85 +++++++++++++++++++ .../resource_vector_search_endpoint_test.go | 17 ++++ 4 files changed, 150 insertions(+) create mode 100644 docs/resources/vector_search_endpoint.md create mode 100644 vectorsearch/resource_vector_search_endpoint.go create mode 100644 vectorsearch/resource_vector_search_endpoint_test.go diff --git a/docs/resources/vector_search_endpoint.md b/docs/resources/vector_search_endpoint.md new file mode 100644 index 0000000000..e96e6d9521 --- /dev/null +++ b/docs/resources/vector_search_endpoint.md @@ -0,0 +1,46 @@ +--- +subcategory: "Vector Search" +--- +# databricks_vector_search_endpoint Resource + +This resource allows you to create [Vector Search Endpoint](https://docs.databricks.com/en/generative-ai/vector-search.html) in Databricks. Vector Search is a serverless similarity search engine that allows you to store a vector representation of your data, including metadata, in a vector database. The Vector Search Endpoint is used to create and access vector search indexes. + +## Example Usage + + +```hcl +resource "databricks_vector_search_endpoint" "this" { + name = "vector-search-test" + endpoint_type = "STANDARD" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Name of the Vector Search Endpoint to create. If name is changed, Vector Search Endpoint is recreated. +* `endpoint_type` (Required) type of Vector Search Endpoint. Currently only accepting single value: `STANDARD` (See [documentation](https://docs.databricks.com/api/workspace/vectorsearchendpoints/createendpoint) for the list of currently supported values). If it changed, Vector Search Endpoint is recreated. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The same as the name of the endpoint. +* `creator` - Creator of the endpoint. +* `creation_timestamp` - Timestamp of endpoint creation (milliseconds). +* `last_updated_user` - User who last updated the endpoint. +* `last_updated_timestamp` - Timestamp of last update to the endpoint (milliseconds). +* `endpoint_id` - Unique identifier of the endpoint. +* `num_indexes` - Current status of the endpoint. +* `endpoint_status` - Object describing the current status of the endpoint consisting of following fields: + * `state` - Current state of the endpoint. Currently following values are supported: `PROVISIONING`, `ONLINE`, `OFFLINE`. + * `message` - Additional status message. + +## Import + +The resource can be imported using the name of the Vector Search Endpoint + +```bash +terraform import databricks_vector_search_endpoint.this +``` diff --git a/provider/provider.go b/provider/provider.go index 3b0e1dcf66..fbd8f324a6 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -39,6 +39,7 @@ import ( "github.com/databricks/terraform-provider-databricks/sql" "github.com/databricks/terraform-provider-databricks/storage" "github.com/databricks/terraform-provider-databricks/tokens" + "github.com/databricks/terraform-provider-databricks/vectorsearch" "github.com/databricks/terraform-provider-databricks/workspace" ) @@ -173,6 +174,7 @@ func DatabricksProvider() *schema.Provider { "databricks_user": scim.ResourceUser().ToResource(), "databricks_user_instance_profile": aws.ResourceUserInstanceProfile().ToResource(), "databricks_user_role": aws.ResourceUserRole().ToResource(), + "databricks_vector_search_endpoint": vectorsearch.ResourceVectorSearchEndpoint().ToResource(), "databricks_volume": catalog.ResourceVolume().ToResource(), "databricks_workspace_conf": workspace.ResourceWorkspaceConf().ToResource(), "databricks_workspace_file": workspace.ResourceWorkspaceFile().ToResource(), diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go new file mode 100644 index 0000000000..7689dce844 --- /dev/null +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -0,0 +1,85 @@ +package vectorsearch + +import ( + "context" + "time" + + "github.com/databricks/databricks-sdk-go/retries" + "github.com/databricks/terraform-provider-databricks/common" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/databricks/databricks-sdk-go/service/vectorsearch" +) + +const DefaultProvisionTimeout = 45 * time.Minute + +func ResourceVectorSearchEndpoint() *schema.Resource { + s := common.StructToSchema( + vectorsearch.EndpointInfo{}, + func(s map[string]*schema.Schema) map[string]*schema.Schema { + common.CustomizeSchemaPath(s, "name").SetRequired() + s["name"].ForceNew = true + s["endpoint_type"].ForceNew = true + common.CustomizeSchemaPath(s, "endpoint_type").SetRequired() + delete(s, "id") + common.CustomizeSchemaPath(s, "creator").SetReadOnly() + common.CustomizeSchemaPath(s, "creation_timestamp").SetReadOnly() + common.CustomizeSchemaPath(s, "last_updated_timestamp").SetReadOnly() + common.CustomizeSchemaPath(s, "last_updated_user").SetReadOnly() + common.CustomizeSchemaPath(s, "endpoint_status").SetReadOnly() + common.CustomizeSchemaPath(s, "num_indexes").SetReadOnly() + common.CustomizeSchemaPath(s).AddNewField("endpoint_id", &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }) + + return s + }) + + return common.Resource{ + Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { + w, err := c.WorkspaceClient() + if err != nil { + return err + } + var req vectorsearch.CreateEndpoint + common.DataToStructPointer(d, s, &req) + endpoint, err := w.VectorSearchEndpoints.CreateEndpointAndWait(ctx, req, + retries.Timeout[vectorsearch.EndpointInfo](d.Timeout(schema.TimeoutCreate))) + if err != nil { + return err + } + d.SetId(endpoint.Name) + return nil + }, + Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { + w, err := c.WorkspaceClient() + if err != nil { + return err + } + endpoint, err := w.VectorSearchEndpoints.GetEndpointByEndpointName(ctx, d.Id()) + if err != nil { + return err + } + err = common.StructToData(*endpoint, s, d) + if err != nil { + return err + } + d.Set("endpoint_id", endpoint.Id) + return nil + }, + Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { + w, err := c.WorkspaceClient() + if err != nil { + return err + } + return w.VectorSearchEndpoints.DeleteEndpointByEndpointName(ctx, d.Id()) + }, + StateUpgraders: []schema.StateUpgrader{}, + Schema: s, + SchemaVersion: 0, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(DefaultProvisionTimeout), + }, + }.ToResource() +} diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go new file mode 100644 index 0000000000..947c2d47e4 --- /dev/null +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -0,0 +1,17 @@ +package vectorsearch + +import ( + "testing" + + "github.com/databricks/terraform-provider-databricks/qa" + + "github.com/stretchr/testify/assert" +) + +func TestVectorSearchEndpointCornerCases(t *testing.T) { + qa.ResourceCornerCases(t, ResourceVectorSearchEndpoint()) +} + +func TestVectorSearchEndpointCreate(t *testing.T) { + assert.Equal(t, 1, 1) +} From e884d0b8fc405739f47a3ea231bb570caebea759 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Wed, 31 Jan 2024 19:46:00 +0100 Subject: [PATCH 02/14] Add unit tests --- .../resource_vector_search_endpoint_test.go | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go index 947c2d47e4..e87353ce85 100644 --- a/vectorsearch/resource_vector_search_endpoint_test.go +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -3,9 +3,13 @@ package vectorsearch import ( "testing" + "github.com/databricks/databricks-sdk-go/experimental/mocks" "github.com/databricks/terraform-provider-databricks/qa" + "github.com/databricks/databricks-sdk-go/service/vectorsearch" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) func TestVectorSearchEndpointCornerCases(t *testing.T) { @@ -13,5 +17,41 @@ func TestVectorSearchEndpointCornerCases(t *testing.T) { } func TestVectorSearchEndpointCreate(t *testing.T) { - assert.Equal(t, 1, 1) + ei := &vectorsearch.EndpointInfo{ + Name: "abc", + EndpointStatus: &vectorsearch.EndpointStatus{State: "ONLINE"}, + Id: "1234-5678", + } + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + e := w.GetMockVectorSearchEndpointsAPI().EXPECT() + e.CreateEndpointAndWait(mock.Anything, vectorsearch.CreateEndpoint{ + Name: "abc", + EndpointType: "STANDARD", + }, mock.Anything).Return(ei, nil) + e.GetEndpointByEndpointName(mock.Anything, "abc").Return(ei, nil) + }, + Resource: ResourceVectorSearchEndpoint(), + HCL: ` + name = "abc" + endpoint_type = "STANDARD" + `, + Create: true, + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "abc", d.Id()) + assert.Equal(t, "1234-5678", d.Get("endpoint_id")) +} + +func TestResourcePASDelete(t *testing.T) { + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(a *mocks.MockWorkspaceClient) { + a.GetMockVectorSearchEndpointsAPI().EXPECT().DeleteEndpointByEndpointName(mock.Anything, "abc").Return(nil) + }, + Resource: ResourceVectorSearchEndpoint(), + Delete: true, + ID: "abc", + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "abc", d.Id()) } From 2ef938435d952ab91b4a7eb206513a909d8a0e7f Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Wed, 31 Jan 2024 19:50:20 +0100 Subject: [PATCH 03/14] Fix exporter test --- exporter/exporter_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index 4ba68ae64b..303d791ec7 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -2168,6 +2168,7 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ObjectList{ Objects: []workspace.ObjectStatus{notebookStatus, fileStatus}, }, + ReuseRequest: true, }, { Method: "GET", From 7edfb7353c4fc74db3d83954db16578734d22f14 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 11:25:02 +0100 Subject: [PATCH 04/14] Update vectorsearch/resource_vector_search_endpoint.go Co-authored-by: Miles Yucht --- vectorsearch/resource_vector_search_endpoint.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index 7689dce844..afc26b31da 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -17,10 +17,8 @@ func ResourceVectorSearchEndpoint() *schema.Resource { s := common.StructToSchema( vectorsearch.EndpointInfo{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { - common.CustomizeSchemaPath(s, "name").SetRequired() - s["name"].ForceNew = true - s["endpoint_type"].ForceNew = true - common.CustomizeSchemaPath(s, "endpoint_type").SetRequired() + common.CustomizeSchemaPath(s, "name").SetRequired().SetForceNew() + common.CustomizeSchemaPath(s, "endpoint_type").SetRequired().SetForceNew() delete(s, "id") common.CustomizeSchemaPath(s, "creator").SetReadOnly() common.CustomizeSchemaPath(s, "creation_timestamp").SetReadOnly() From ab4b056fdd4c5a7efe5819ed6499ebe981bb8a74 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 11:25:43 +0100 Subject: [PATCH 05/14] Update vectorsearch/resource_vector_search_endpoint.go Co-authored-by: Miles Yucht --- vectorsearch/resource_vector_search_endpoint.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index afc26b31da..e3ea326620 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -42,8 +42,7 @@ func ResourceVectorSearchEndpoint() *schema.Resource { } var req vectorsearch.CreateEndpoint common.DataToStructPointer(d, s, &req) - endpoint, err := w.VectorSearchEndpoints.CreateEndpointAndWait(ctx, req, - retries.Timeout[vectorsearch.EndpointInfo](d.Timeout(schema.TimeoutCreate))) + endpoint, err := w.VectorSearchEndpoints.CreateEndpoint(ctx, req).GetWithTimeout(d.Timeout(schema.TimeoutCreate)) if err != nil { return err } From 024283702457329c52f9157a4a1f09694fe1c2f1 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 11:43:15 +0100 Subject: [PATCH 06/14] Fix commited code --- exporter/exporter_test.go | 17 ++++++----------- vectorsearch/resource_vector_search_endpoint.go | 7 +++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index 303d791ec7..e1a758305b 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -2168,19 +2168,16 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ObjectList{ Objects: []workspace.ObjectStatus{notebookStatus, fileStatus}, }, - ReuseRequest: true, }, { - Method: "GET", - Resource: "/api/2.0/workspace/get-status?path=%2FNotebook", - Response: notebookStatus, - ReuseRequest: true, + Method: "GET", + Resource: "/api/2.0/workspace/get-status?path=%2FNotebook", + Response: notebookStatus, }, { - Method: "GET", - Resource: "/api/2.0/workspace/get-status?path=%2FFile", - Response: fileStatus, - ReuseRequest: true, + Method: "GET", + Resource: "/api/2.0/workspace/get-status?path=%2FFile", + Response: fileStatus, }, { Method: "GET", @@ -2188,7 +2185,6 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ExportPath{ Content: "dGVzdA==", }, - ReuseRequest: true, }, { Method: "GET", @@ -2196,7 +2192,6 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ExportPath{ Content: "dGVzdA==", }, - ReuseRequest: true, }, }, func(ctx context.Context, client *common.DatabricksClient) { diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index e3ea326620..baa260bcb6 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/databricks/databricks-sdk-go/retries" "github.com/databricks/terraform-provider-databricks/common" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -42,7 +41,11 @@ func ResourceVectorSearchEndpoint() *schema.Resource { } var req vectorsearch.CreateEndpoint common.DataToStructPointer(d, s, &req) - endpoint, err := w.VectorSearchEndpoints.CreateEndpoint(ctx, req).GetWithTimeout(d.Timeout(schema.TimeoutCreate)) + wait, err := w.VectorSearchEndpoints.CreateEndpoint(ctx, req) + if err != nil { + return err + } + endpoint, err := wait.GetWithTimeout(d.Timeout(schema.TimeoutCreate)) if err != nil { return err } From 1519a28a0fc10cffca594e126ce64fb35a296ab9 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 11:49:22 +0100 Subject: [PATCH 07/14] Fix incorrect rebase --- exporter/exporter_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index e1a758305b..303d791ec7 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -2168,16 +2168,19 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ObjectList{ Objects: []workspace.ObjectStatus{notebookStatus, fileStatus}, }, + ReuseRequest: true, }, { - Method: "GET", - Resource: "/api/2.0/workspace/get-status?path=%2FNotebook", - Response: notebookStatus, + Method: "GET", + Resource: "/api/2.0/workspace/get-status?path=%2FNotebook", + Response: notebookStatus, + ReuseRequest: true, }, { - Method: "GET", - Resource: "/api/2.0/workspace/get-status?path=%2FFile", - Response: fileStatus, + Method: "GET", + Resource: "/api/2.0/workspace/get-status?path=%2FFile", + Response: fileStatus, + ReuseRequest: true, }, { Method: "GET", @@ -2185,6 +2188,7 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ExportPath{ Content: "dGVzdA==", }, + ReuseRequest: true, }, { Method: "GET", @@ -2192,6 +2196,7 @@ func TestImportingNotebooksWorkspaceFiles(t *testing.T) { Response: workspace.ExportPath{ Content: "dGVzdA==", }, + ReuseRequest: true, }, }, func(ctx context.Context, client *common.DatabricksClient) { From d4612a25e14dfeb11637a645e79e1b48156e6e62 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 12:38:43 +0100 Subject: [PATCH 08/14] Fix mocked tests --- vectorsearch/resource_vector_search_endpoint_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go index e87353ce85..6c19cf50a3 100644 --- a/vectorsearch/resource_vector_search_endpoint_test.go +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/databricks/databricks-sdk-go/experimental/mocks" + "github.com/databricks/databricks-sdk-go/qa/poll" "github.com/databricks/terraform-provider-databricks/qa" "github.com/databricks/databricks-sdk-go/service/vectorsearch" @@ -25,10 +26,11 @@ func TestVectorSearchEndpointCreate(t *testing.T) { d, err := qa.ResourceFixture{ MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { e := w.GetMockVectorSearchEndpointsAPI().EXPECT() - e.CreateEndpointAndWait(mock.Anything, vectorsearch.CreateEndpoint{ + e.CreateEndpoint(mock.Anything, vectorsearch.CreateEndpoint{ Name: "abc", EndpointType: "STANDARD", - }, mock.Anything).Return(ei, nil) + }).Return(&vectorsearch.WaitGetEndpointVectorSearchEndpointOnline[vectorsearch.EndpointInfo]{Poll: poll.Simple(*ei)}, nil) + e.GetEndpointByEndpointName(mock.Anything, "abc").Return(ei, nil) }, Resource: ResourceVectorSearchEndpoint(), From b6b0e31e58f3821d011a6b98f082323d7cc1035f Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Thu, 1 Feb 2024 13:45:30 +0100 Subject: [PATCH 09/14] adjust the code --- vectorsearch/resource_vector_search_endpoint.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index baa260bcb6..c9647fa316 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -12,7 +12,7 @@ import ( const DefaultProvisionTimeout = 45 * time.Minute -func ResourceVectorSearchEndpoint() *schema.Resource { +func ResourceVectorSearchEndpoint() common.Resource { s := common.StructToSchema( vectorsearch.EndpointInfo{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { @@ -81,5 +81,5 @@ func ResourceVectorSearchEndpoint() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(DefaultProvisionTimeout), }, - }.ToResource() + } } From 2e95c2d74778fd722cb6b1cde25594ced0673b55 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 2 Feb 2024 16:08:21 +0100 Subject: [PATCH 10/14] Add acceptance test --- internal/acceptance/vector_search_test.go | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 internal/acceptance/vector_search_test.go diff --git a/internal/acceptance/vector_search_test.go b/internal/acceptance/vector_search_test.go new file mode 100644 index 0000000000..383a867e04 --- /dev/null +++ b/internal/acceptance/vector_search_test.go @@ -0,0 +1,30 @@ +package acceptance + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" +) + +func TestAccVectorSearchEndpoint(t *testing.T) { + cloudEnv := os.Getenv("CLOUD_ENV") + switch cloudEnv { + case "aws", "azure": + default: + t.Skipf("not available on %s", cloudEnv) + } + + name := fmt.Sprintf("terraform-test-vector-search-%[1]s", + acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + workspaceLevel(t, step{ + Template: fmt.Sprintf(` + resource "databricks_vector_search_endpoint" "this" { + name = "%s" + endpoint_type = "STANDARD" + } + `, name), + }, + ) +} From 0484a4dcebfb628e9eaddde1a68018f7e42be157 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 2 Feb 2024 16:49:46 +0100 Subject: [PATCH 11/14] Fix integration test, add a warning about UC workspace --- docs/resources/vector_search_endpoint.md | 4 +++- internal/acceptance/vector_search_test.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/resources/vector_search_endpoint.md b/docs/resources/vector_search_endpoint.md index e96e6d9521..562d869d31 100644 --- a/docs/resources/vector_search_endpoint.md +++ b/docs/resources/vector_search_endpoint.md @@ -3,7 +3,9 @@ subcategory: "Vector Search" --- # databricks_vector_search_endpoint Resource -This resource allows you to create [Vector Search Endpoint](https://docs.databricks.com/en/generative-ai/vector-search.html) in Databricks. Vector Search is a serverless similarity search engine that allows you to store a vector representation of your data, including metadata, in a vector database. The Vector Search Endpoint is used to create and access vector search indexes. +-> **Note** This resource could be only used on Unity Catalog-enabled workspace! + +This resource allows you to create [Vector Search Endpoint](https://docs.databricks.com/en/generative-ai/vector-search.html) in Databricks. Vector Search is a serverless similarity search engine that allows you to store a vector representation of your data, including metadata, in a vector database. The Vector Search Endpoint is used to create and access vector search indexes. ## Example Usage diff --git a/internal/acceptance/vector_search_test.go b/internal/acceptance/vector_search_test.go index 383a867e04..fa47e13479 100644 --- a/internal/acceptance/vector_search_test.go +++ b/internal/acceptance/vector_search_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" ) -func TestAccVectorSearchEndpoint(t *testing.T) { +func TestUcAccVectorSearchEndpoint(t *testing.T) { cloudEnv := os.Getenv("CLOUD_ENV") switch cloudEnv { case "aws", "azure": @@ -18,7 +18,7 @@ func TestAccVectorSearchEndpoint(t *testing.T) { name := fmt.Sprintf("terraform-test-vector-search-%[1]s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) - workspaceLevel(t, step{ + unityWorkspaceLevel(t, step{ Template: fmt.Sprintf(` resource "databricks_vector_search_endpoint" "this" { name = "%s" From f82ef570402f325c66b265c334cf9c4f9f42220d Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 2 Feb 2024 17:09:44 +0100 Subject: [PATCH 12/14] Fix environment name for AWS UC-enabled workspace --- internal/acceptance/vector_search_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/acceptance/vector_search_test.go b/internal/acceptance/vector_search_test.go index fa47e13479..b6c45f73b8 100644 --- a/internal/acceptance/vector_search_test.go +++ b/internal/acceptance/vector_search_test.go @@ -11,7 +11,7 @@ import ( func TestUcAccVectorSearchEndpoint(t *testing.T) { cloudEnv := os.Getenv("CLOUD_ENV") switch cloudEnv { - case "aws", "azure": + case "ucws", "azure": default: t.Skipf("not available on %s", cloudEnv) } @@ -22,7 +22,7 @@ func TestUcAccVectorSearchEndpoint(t *testing.T) { Template: fmt.Sprintf(` resource "databricks_vector_search_endpoint" "this" { name = "%s" - endpoint_type = "STANDARD" + mendpoint_type = "STANDARD" } `, name), }, From 38cc2b05341075d7e09099f9692763eccb4923cc Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Fri, 2 Feb 2024 17:19:58 +0100 Subject: [PATCH 13/14] Fix typo --- internal/acceptance/vector_search_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/acceptance/vector_search_test.go b/internal/acceptance/vector_search_test.go index b6c45f73b8..a6033aa802 100644 --- a/internal/acceptance/vector_search_test.go +++ b/internal/acceptance/vector_search_test.go @@ -22,7 +22,7 @@ func TestUcAccVectorSearchEndpoint(t *testing.T) { Template: fmt.Sprintf(` resource "databricks_vector_search_endpoint" "this" { name = "%s" - mendpoint_type = "STANDARD" + endpoint_type = "STANDARD" } `, name), }, From 662e960c24b5fa6532f8c886e7449ab0dbefa349 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Wed, 14 Feb 2024 15:37:26 +0100 Subject: [PATCH 14/14] Resolve review comments --- docs/resources/vector_search_endpoint.md | 6 ++--- .../resource_vector_search_endpoint_test.go | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/resources/vector_search_endpoint.md b/docs/resources/vector_search_endpoint.md index 562d869d31..3553c8c7c2 100644 --- a/docs/resources/vector_search_endpoint.md +++ b/docs/resources/vector_search_endpoint.md @@ -22,7 +22,7 @@ resource "databricks_vector_search_endpoint" "this" { The following arguments are supported: * `name` - (Required) Name of the Vector Search Endpoint to create. If name is changed, Vector Search Endpoint is recreated. -* `endpoint_type` (Required) type of Vector Search Endpoint. Currently only accepting single value: `STANDARD` (See [documentation](https://docs.databricks.com/api/workspace/vectorsearchendpoints/createendpoint) for the list of currently supported values). If it changed, Vector Search Endpoint is recreated. +* `endpoint_type` (Required) type of Vector Search Endpoint. Currently only accepting single value: `STANDARD` (See [documentation](https://docs.databricks.com/api/workspace/vectorsearchendpoints/createendpoint) for the list of currently supported values). If it's changed, Vector Search Endpoint is recreated. ## Attribute Reference @@ -33,8 +33,8 @@ In addition to all arguments above, the following attributes are exported: * `creation_timestamp` - Timestamp of endpoint creation (milliseconds). * `last_updated_user` - User who last updated the endpoint. * `last_updated_timestamp` - Timestamp of last update to the endpoint (milliseconds). -* `endpoint_id` - Unique identifier of the endpoint. -* `num_indexes` - Current status of the endpoint. +* `endpoint_id` - Unique internal identifier of the endpoint (UUID). +* `num_indexes` - Number of indexes on the endpoint. * `endpoint_status` - Object describing the current status of the endpoint consisting of following fields: * `state` - Current state of the endpoint. Currently following values are supported: `PROVISIONING`, `ONLINE`, `OFFLINE`. * `message` - Additional status message. diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go index 6c19cf50a3..ec5e193a57 100644 --- a/vectorsearch/resource_vector_search_endpoint_test.go +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -45,6 +45,30 @@ func TestVectorSearchEndpointCreate(t *testing.T) { assert.Equal(t, "1234-5678", d.Get("endpoint_id")) } +func TestVectorSearchEndpointRead(t *testing.T) { + ei := &vectorsearch.EndpointInfo{ + Name: "abc", + EndpointStatus: &vectorsearch.EndpointStatus{State: "ONLINE"}, + Id: "1234-5678", + } + d, err := qa.ResourceFixture{ + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { + e := w.GetMockVectorSearchEndpointsAPI().EXPECT() + e.GetEndpointByEndpointName(mock.Anything, "abc").Return(ei, nil) + }, + Resource: ResourceVectorSearchEndpoint(), + ID: "abc", + HCL: ` + name = "abc" + endpoint_type = "STANDARD" + `, + Read: true, + }.Apply(t) + assert.NoError(t, err) + assert.Equal(t, "abc", d.Id()) + assert.Equal(t, "1234-5678", d.Get("endpoint_id")) +} + func TestResourcePASDelete(t *testing.T) { d, err := qa.ResourceFixture{ MockWorkspaceClientFunc: func(a *mocks.MockWorkspaceClient) {