Skip to content

Commit

Permalink
Delete Vector Search Endpoint when we get an error while waiting for …
Browse files Browse the repository at this point in the history
…creation (#3348)

* Delete Vector Search Endpoint when we get an error while waiting for creation

If we get an error while waiting for the endpoint creation we simply return that
error.  But when we got timeout, we didn't cleanup the endpoint and this lead that
resource isn't destroyed in the tests as backend continued to provision it.

This PR deletes vector search endpoint when we got creation error during the wait phase.
This behaviour is similar to the current behavior of clusters.

* address review comments

* Adjust based on the discussion
  • Loading branch information
alexott authored Mar 11, 2024
1 parent d29070e commit f591dda
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions vectorsearch/resource_vector_search_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vectorsearch

import (
"context"
"log"
"time"

"github.com/databricks/terraform-provider-databricks/common"
Expand All @@ -10,7 +11,8 @@ import (
"github.com/databricks/databricks-sdk-go/service/vectorsearch"
)

const DefaultProvisionTimeout = 75 * time.Minute
const defaultProvisionTimeout = 75 * time.Minute
const deleteCallTimeout = 10 * time.Second

func ResourceVectorSearchEndpoint() common.Resource {
s := common.StructToSchema(
Expand Down Expand Up @@ -45,8 +47,13 @@ func ResourceVectorSearchEndpoint() common.Resource {
if err != nil {
return err
}
endpoint, err := wait.GetWithTimeout(d.Timeout(schema.TimeoutCreate))
endpoint, err := wait.GetWithTimeout(d.Timeout(schema.TimeoutCreate) - deleteCallTimeout)
if err != nil {
log.Printf("[ERROR] Error waiting for endpoint to be created: %s", err.Error())
nestedErr := w.VectorSearchEndpoints.DeleteEndpointByEndpointName(ctx, req.Name)
if nestedErr != nil {
log.Printf("[ERROR] Error cleaning up endpoint: %s", nestedErr.Error())
}
return err
}
d.SetId(endpoint.Name)
Expand Down Expand Up @@ -79,7 +86,7 @@ func ResourceVectorSearchEndpoint() common.Resource {
Schema: s,
SchemaVersion: 0,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(DefaultProvisionTimeout),
Create: schema.DefaultTimeout(defaultProvisionTimeout),
},
}
}
26 changes: 26 additions & 0 deletions vectorsearch/resource_vector_search_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package vectorsearch

import (
"fmt"
"testing"
"time"

"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/qa/poll"
Expand Down Expand Up @@ -81,3 +83,27 @@ func TestResourcePASDelete(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "abc", d.Id())
}

func TestVectorSearchEndpointCreateTimeoutError(t *testing.T) {
qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
e := w.GetMockVectorSearchEndpointsAPI().EXPECT()
e.CreateEndpoint(mock.Anything, vectorsearch.CreateEndpoint{
Name: "abc",
EndpointType: "STANDARD",
}).Return(&vectorsearch.WaitGetEndpointVectorSearchEndpointOnline[vectorsearch.EndpointInfo]{
Poll: func(_ time.Duration, _ func(*vectorsearch.EndpointInfo)) (*vectorsearch.EndpointInfo, error) {
return nil, fmt.Errorf("timeout")
},
}, nil)
e.DeleteEndpointByEndpointName(mock.Anything, "abc").Return(nil)
},
Resource: ResourceVectorSearchEndpoint(),
HCL: `
name = "abc"
endpoint_type = "STANDARD"
`,
Create: true,
}.ExpectError(t, "timeout")

}

0 comments on commit f591dda

Please sign in to comment.