diff --git a/vectorsearch/resource_vector_search_endpoint.go b/vectorsearch/resource_vector_search_endpoint.go index fb8b324d1a..7ca39af680 100644 --- a/vectorsearch/resource_vector_search_endpoint.go +++ b/vectorsearch/resource_vector_search_endpoint.go @@ -2,6 +2,7 @@ package vectorsearch import ( "context" + "log" "time" "github.com/databricks/terraform-provider-databricks/common" @@ -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( @@ -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) @@ -79,7 +86,7 @@ func ResourceVectorSearchEndpoint() common.Resource { Schema: s, SchemaVersion: 0, Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(DefaultProvisionTimeout), + Create: schema.DefaultTimeout(defaultProvisionTimeout), }, } } diff --git a/vectorsearch/resource_vector_search_endpoint_test.go b/vectorsearch/resource_vector_search_endpoint_test.go index ec5e193a57..061f9bc16d 100644 --- a/vectorsearch/resource_vector_search_endpoint_test.go +++ b/vectorsearch/resource_vector_search_endpoint_test.go @@ -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" @@ -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") + +}