Skip to content

Commit 43b4996

Browse files
authored
Skip lib refresh for clusters with no libs (#1024)
Allowed managing of libraries on `databricks_cluster` outside of Terraform state for resources without any `library` configuration blocks. **Behavior changes** * Whenever library is installed on `databricks_cluster` without any [`library` configuration blocks](https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs/resources/cluster#library-configuration-block), it won't be removed anymore.
1 parent 0aeb799 commit 43b4996

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
## 0.4.4
44

55
* Added support for [running provider in a debug mode](https://www.terraform.io/plugin/sdkv2/debugging#running-terraform-with-a-provider-in-debug-mode) from Visual Studio Code through `Debug Provider` run configuration in order to troubleshoot more complicated issues.
6+
* Allowed managing of libraries on `databricks_cluster` outside of Terraform state for resources without any `library` configuration blocks. This should simplify PaaS-like CI/CD workflows.
7+
8+
**Behavior changes**
9+
10+
* Whenever library is installed on `databricks_cluster` without any [`library` configuration blocks](https://registry.terraform.io/providers/databrickslabs/databricks/latest/docs/resources/cluster#library-configuration-block), it won't be removed anymore.
611

712
## 0.4.3
813

clusters/resource_cluster.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, c *common.
195195
return err
196196
}
197197
d.Set("url", c.FormatURL("#setting/clusters/", d.Id(), "/configuration"))
198+
if d.Get("library.#").(int) == 0 {
199+
// don't add externally added libraries, if config has no `library {}` blocks
200+
// TODO: check if it still works fine with importing. Perhaps os.Setenv will do the trick
201+
return nil
202+
}
198203
librariesAPI := libraries.NewLibrariesAPI(ctx, c)
199204
libsClusterStatus, err := librariesAPI.WaitForLibrariesInstalled(libraries.Wait{
200205
ClusterID: d.Id(),
@@ -269,7 +274,11 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, c *commo
269274
return err
270275
}
271276
}
272-
277+
oldNumLibs, newNumLibs := d.GetChange("library.#")
278+
if oldNumLibs == newNumLibs && oldNumLibs.(int) == 0 {
279+
// don't add externally added libraries, if config has no `library {}` blocks
280+
return nil
281+
}
273282
var libraryList libraries.ClusterLibraryList
274283
common.DataToStructPointer(d, clusterSchema, &libraryList)
275284
librariesAPI := libraries.NewLibrariesAPI(ctx, c)

clusters/resource_cluster_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -419,22 +419,6 @@ func TestResourceClusterRead(t *testing.T) {
419419
TotalCount: 0,
420420
},
421421
},
422-
{
423-
Method: "GET",
424-
Resource: "/api/2.0/libraries/cluster-status?cluster_id=abc",
425-
Response: libraries.ClusterLibraryStatuses{
426-
LibraryStatuses: []libraries.LibraryStatus{
427-
{
428-
Library: &libraries.Library{
429-
Pypi: &libraries.PyPi{
430-
Package: "requests",
431-
},
432-
},
433-
Status: "INSTALLED",
434-
},
435-
},
436-
},
437-
},
438422
},
439423
Resource: ResourceCluster(),
440424
Read: true,
@@ -447,7 +431,6 @@ func TestResourceClusterRead(t *testing.T) {
447431
assert.Equal(t, "Shared Autoscaling", d.Get("cluster_name"))
448432
assert.Equal(t, "i3.xlarge", d.Get("node_type_id"))
449433
assert.Equal(t, 4, d.Get("autoscale.0.max_workers"))
450-
assert.Equal(t, "requests", d.Get("library.2047590238.pypi.0.package"))
451434
assert.Equal(t, "RUNNING", d.Get("state"))
452435
assert.Equal(t, false, d.Get("is_pinned"))
453436

0 commit comments

Comments
 (0)