Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Restart Cluster before Library Installation #4384

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ func (r *LibraryResource) Create(ctx context.Context, req resource.CreateRequest
Libraries: []compute.Library{libGoSDK},
}
req.Plan.GetAttribute(ctx, path.Root("cluster_id"), &installLib.ClusterId)
err := w.Libraries.Install(ctx, installLib)
_, err := clusters.StartClusterAndGetInfo(ctx, w, installLib.ClusterId)
if err != nil {
resp.Diagnostics.AddError("failed to start and get cluster", err.Error())
return
}
err = w.Libraries.Install(ctx, installLib)
if err != nil {
resp.Diagnostics.AddError("failed to install library", err.Error())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/retries"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/databricks/terraform-provider-databricks/internal/providers"
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw"
Expand Down Expand Up @@ -63,7 +65,7 @@ func TestAccLibraryReinstalledIfClusterDeleted(t *testing.T) {
return nil
},
},
// If the cluster is terminated before apply, it should be restarted and the library reinstalled.
// If the cluster is deleted before apply, it should be recreated and the library reinstalled on the new cluster.
acceptance.Step{
PreConfig: func() {
// Delete the created cluster
Expand Down Expand Up @@ -92,6 +94,42 @@ func TestAccLibraryReinstalledIfClusterDeleted(t *testing.T) {
})
}

func TestAccLibraryInstallIfClusterTerminated(t *testing.T) {
var clusterId string
acceptance.WorkspaceLevel(t,
acceptance.Step{
Template: commonClusterConfig,
Check: func(s *terraform.State) error {
clusterId = s.RootModule().Resources["databricks_cluster.this"].Primary.ID
return nil
},
},
// If the cluster is Terminated before apply, it should be restarted before installing library.
acceptance.Step{
PreConfig: func() {
// Delete the created cluster
w := databricks.Must(databricks.NewWorkspaceClient())
getter, err := w.Clusters.Delete(context.Background(), compute.DeleteCluster{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a confusing name for this method... @renaudhartert-db maybe we want to revisit this in the next version of the SDK. It should really be "terminate cluster" to align with basically all other terminology.

ClusterId: clusterId,
})
if err != nil {
t.Fatalf("Error deleting cluster: %s", err)
}
_, err = getter.GetWithTimeout(60 * time.Minute)
if err != nil {
t.Fatalf("Error waiting for cluster to be deleted: %s", err)
}
},
Template: commonClusterConfig + `resource "databricks_library" "new_library" {
cluster_id = databricks_cluster.this.id
pypi {
repo = "https://pypi.org/dummy"
package = "databricks-sdk"
}
}`,
})
}

func TestAccLibraryUpdate(t *testing.T) {
acceptance.WorkspaceLevel(t,
acceptance.Step{
Expand Down
Loading