Skip to content

Commit e3236b5

Browse files
authored
Don't restart cluster on non-related configuration changes (#379) (#385)
1 parent c28b209 commit e3236b5

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Version changelog
22

3+
## 0.2.9
4+
5+
* Fixed restarting cluster on changes in cluster configuration aren't related to the cluster configuration ([issue #379](https://github.com/databrickslabs/terraform-provider-databricks/issues/379))
6+
37
## 0.2.8
48

59
* Added [databricks_workspace_conf](https://github.com/databrickslabs/terraform-provider-databricks/pull/398) resource

compute/resource_cluster.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
var clusterSchema = resourceClusterSchema()
1515

16+
// ResourceCluster - returns Cluster resource description
1617
func ResourceCluster() *schema.Resource {
1718
return &schema.Resource{
1819
SchemaVersion: 2,
@@ -282,6 +283,19 @@ func legacyReadLibraryListFromData(d *schema.ResourceData) (cll ClusterLibraryLi
282283
return
283284
}
284285

286+
func hasClusterConfigChanged(d *schema.ResourceData) bool {
287+
for k := range clusterSchema {
288+
// TODO: create a map if we'll add more non-cluster config parameters in the future
289+
if k == "library" || k == "is_pinned" {
290+
continue
291+
}
292+
if d.HasChange(k) {
293+
return true
294+
}
295+
}
296+
return false
297+
}
298+
285299
func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error {
286300
client := m.(*common.DatabricksClient)
287301
clusters := NewClustersAPI(client)
@@ -291,18 +305,27 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error {
291305
if err != nil {
292306
return err
293307
}
294-
modifyClusterRequest(&cluster)
295-
clusterInfo, err := clusters.Edit(cluster)
296-
if err != nil {
297-
return err
308+
var clusterInfo ClusterInfo
309+
if hasClusterConfigChanged(d) {
310+
log.Printf("[DEBUG] Cluster state has changed!")
311+
modifyClusterRequest(&cluster)
312+
clusterInfo, err = clusters.Edit(cluster)
313+
if err != nil {
314+
return err
315+
}
316+
} else {
317+
clusterInfo, err = clusters.Get(clusterID)
318+
if err != nil {
319+
return err
320+
}
298321
}
299322
oldPinned, newPinned := d.GetChange("is_pinned")
300323
if oldPinned.(bool) != newPinned.(bool) {
301324
log.Printf("[DEBUG] Update: is_pinned. Old: %v, New: %v", oldPinned, newPinned)
302325
if newPinned.(bool) {
303-
err = clusters.Pin(clusterInfo.ClusterID)
326+
err = clusters.Pin(clusterID)
304327
} else {
305-
err = clusters.Unpin(clusterInfo.ClusterID)
328+
err = clusters.Unpin(clusterID)
306329
}
307330
if err != nil {
308331
return err

compute/resource_cluster_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -826,18 +826,6 @@ func TestResourceClusterUpdateWithPinned(t *testing.T) {
826826
LibraryStatuses: []LibraryStatus{},
827827
},
828828
},
829-
{
830-
Method: "POST",
831-
Resource: "/api/2.0/clusters/edit",
832-
ExpectedRequest: Cluster{
833-
AutoterminationMinutes: 15,
834-
ClusterID: "abc",
835-
NumWorkers: 100,
836-
ClusterName: "Shared Autoscaling",
837-
SparkVersion: "7.1-scala12",
838-
NodeTypeID: "i3.xlarge",
839-
},
840-
},
841829
{
842830
Method: "POST",
843831
Resource: "/api/2.0/clusters/pin",
@@ -854,6 +842,13 @@ func TestResourceClusterUpdateWithPinned(t *testing.T) {
854842
ID: "abc",
855843
Update: true,
856844
Resource: ResourceCluster(),
845+
InstanceState: map[string]string{
846+
"autotermination_minutes": "15",
847+
"cluster_name": "Shared Autoscaling",
848+
"spark_version": "7.1-scala12",
849+
"node_type_id": "i3.xlarge",
850+
"num_workers": "100",
851+
},
857852
State: map[string]interface{}{
858853
"autotermination_minutes": 15,
859854
"cluster_name": "Shared Autoscaling",

0 commit comments

Comments
 (0)