Skip to content

Commit dac4252

Browse files
authored
Delete permissions resource for auto-purged cluster (#1252)
Fix #1227
1 parent 24907f5 commit dac4252

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

permissions/resource_permissions.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ func (a PermissionsAPI) Delete(objectID string) error {
203203
// Read gets all relevant permissions for the object, including inherited ones
204204
func (a PermissionsAPI) Read(objectID string) (objectACL ObjectACL, err error) {
205205
err = a.client.Get(a.context, urlPathForObjectID(objectID), nil, &objectACL)
206+
apiErr, ok := err.(common.APIError)
207+
// https://github.com/databrickslabs/terraform-provider-databricks/issues/1227
208+
// platform propagates INVALID_STATE error for auto-purged clusters in
209+
// the permissions api. this adds "a logical fix" also here, not to introduce
210+
// cross-package dependency on "clusters".
211+
if ok && strings.Contains(apiErr.Message, "Cannot access cluster") {
212+
apiErr.StatusCode = 404
213+
err = apiErr
214+
return
215+
}
206216
return
207217
}
208218

permissions/resource_permissions_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ func TestResourcePermissionsRead(t *testing.T) {
9898
assert.Equal(t, "CAN_READ", firstElem["permission_level"])
9999
}
100100

101+
// https://github.com/databrickslabs/terraform-provider-databricks/issues/1227
102+
func TestResourcePermissionsRead_RemovedCluster(t *testing.T) {
103+
qa.ResourceFixture{
104+
Fixtures: []qa.HTTPFixture{
105+
me,
106+
{
107+
Method: http.MethodGet,
108+
Resource: "/api/2.0/permissions/clusters/abc",
109+
Status: 400,
110+
Response: common.APIError{
111+
ErrorCode: "INVALID_STATE",
112+
Message: "Cannot access cluster X that was terminated or unpinned more than Y days ago.",
113+
},
114+
},
115+
},
116+
Resource: ResourcePermissions(),
117+
Read: true,
118+
New: true,
119+
Removed: true,
120+
ID: "/clusters/abc",
121+
}.ApplyNoError(t)
122+
}
123+
101124
func TestResourcePermissionsRead_SQLA_Asset(t *testing.T) {
102125
d, err := qa.ResourceFixture{
103126
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)