Skip to content

Commit

Permalink
Delete permissions resource for auto-purged cluster (#1252)
Browse files Browse the repository at this point in the history
Fix #1227
  • Loading branch information
nfx committed Apr 22, 2022
1 parent 24907f5 commit dac4252
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions permissions/resource_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ func (a PermissionsAPI) Delete(objectID string) error {
// Read gets all relevant permissions for the object, including inherited ones
func (a PermissionsAPI) Read(objectID string) (objectACL ObjectACL, err error) {
err = a.client.Get(a.context, urlPathForObjectID(objectID), nil, &objectACL)
apiErr, ok := err.(common.APIError)
// https://github.com/databrickslabs/terraform-provider-databricks/issues/1227
// platform propagates INVALID_STATE error for auto-purged clusters in
// the permissions api. this adds "a logical fix" also here, not to introduce
// cross-package dependency on "clusters".
if ok && strings.Contains(apiErr.Message, "Cannot access cluster") {
apiErr.StatusCode = 404
err = apiErr
return
}
return
}

Expand Down
23 changes: 23 additions & 0 deletions permissions/resource_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ func TestResourcePermissionsRead(t *testing.T) {
assert.Equal(t, "CAN_READ", firstElem["permission_level"])
}

// https://github.com/databrickslabs/terraform-provider-databricks/issues/1227
func TestResourcePermissionsRead_RemovedCluster(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
me,
{
Method: http.MethodGet,
Resource: "/api/2.0/permissions/clusters/abc",
Status: 400,
Response: common.APIError{
ErrorCode: "INVALID_STATE",
Message: "Cannot access cluster X that was terminated or unpinned more than Y days ago.",
},
},
},
Resource: ResourcePermissions(),
Read: true,
New: true,
Removed: true,
ID: "/clusters/abc",
}.ApplyNoError(t)
}

func TestResourcePermissionsRead_SQLA_Asset(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down

0 comments on commit dac4252

Please sign in to comment.