Skip to content

Commit 15bca2c

Browse files
authored
Treat auto-purged databricks_cluster as removed (#1178)
Added special case for handling `Cannot access cluster that was terminated or unpinned more than 30 days ago` error in `databricks_cluster` as an indication of resource removed on the platform side. Fix #1177
1 parent a459c15 commit 15bca2c

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Removed client-side validation in `databricks_service_principal` for `application_id`, that may not always be available in the planning stage ([#1165](https://github.com/databrickslabs/terraform-provider-databricks/issues/1165)).
77
* Use correct HTTP verb for modifying `databricks_permissions` on `databricks_sql_endpoint` entities. Authorized user, assumingly part of `admins` group, is no longer sending `CAN_MANAGE` permission in the HTTP PUT request ([#1163](https://github.com/databrickslabs/terraform-provider-databricks/issues/1163)).
88
* Added diff suppression for `min_num_clusters` field in `databricks_sql_endpoint` ([#1172](https://github.com/databrickslabs/terraform-provider-databricks/pull/1172)).
9+
* Added special case for handling `Cannot access cluster that was terminated or unpinned more than 30 days ago` error in `databricks_cluster` as an indication of resource removed on the platform side ([#1177](https://github.com/databrickslabs/terraform-provider-databricks/issues/1177)).
910

1011
Updated dependency versions:
1112

clusters/clusters_api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ func (a ClustersAPI) StartAndGetInfo(clusterID string) (ClusterInfo, error) {
600600
return a.waitForClusterStatus(clusterID, ClusterStateRunning)
601601
}
602602

603+
// make common/resource.go#ToResource read behavior consistent with "normal" resources
603604
func wrapMissingClusterError(err error, id string) error {
604605
if err == nil {
605606
return nil
@@ -611,6 +612,14 @@ func wrapMissingClusterError(err error, id string) error {
611612
if apiErr.IsMissing() {
612613
return err
613614
}
615+
// https://github.com/databrickslabs/terraform-provider-databricks/issues/1177
616+
// Aligned with Clusters Core team to keep behavior of these workarounds
617+
// as is in the longer term, so that this keeps working.
618+
if apiErr.ErrorCode == "INVALID_STATE" {
619+
log.Printf("[WARN] assuming that cluster is removed on backend: %s", apiErr)
620+
apiErr.StatusCode = 404
621+
return apiErr
622+
}
614623
// fix non-compliant error code
615624
if strings.Contains(apiErr.Message,
616625
fmt.Sprintf("Cluster %s does not exist", id)) {

clusters/clusters_api_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,3 +1202,12 @@ func TestWrapMissingClusterError(t *testing.T) {
12021202
Message: "Cluster abc does not exist",
12031203
}, "abc"), "Cluster abc does not exist")
12041204
}
1205+
1206+
func TestExpiredClusterAssumedAsRemoved(t *testing.T) {
1207+
err := wrapMissingClusterError(common.APIError{
1208+
ErrorCode: "INVALID_STATE",
1209+
Message: "Cannot access cluster X that was terminated or unpinned more than Y days ago.",
1210+
}, "X")
1211+
ae, _ := err.(common.APIError)
1212+
assert.Equal(t, 404, ae.StatusCode)
1213+
}

0 commit comments

Comments
 (0)