Skip to content

Commit a459c15

Browse files
authored
Use correct verb for permissions on SQL Endpoint (#1172)
* Use correct verb for permissions on SQL Endpoint Use correct HTTP verb for `databricks_permissions` on `databricks_sql_endpoint`. Authorized user, assumingly part of `admins` group, is no longer sending `CAN_MANAGE` permission in the HTTP PUT request. Fixes #1163
1 parent 8c0a19e commit a459c15

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Failures in [exporter](https://asciinema.org/a/Rv8ZFJQpfrfp6ggWddjtyXaOy) resource listing no longer halt the entire command run ([#1166](https://github.com/databrickslabs/terraform-provider-databricks/issues/1166)).
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)).
7+
* 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)).
8+
* Added diff suppression for `min_num_clusters` field in `databricks_sql_endpoint` ([#1172](https://github.com/databrickslabs/terraform-provider-databricks/pull/1172)).
79

810
Updated dependency versions:
911

permissions/resource_permissions.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ type PermissionsAPI struct {
111111
context context.Context
112112
}
113113

114+
func isDbsqlPermissionsWorkaroundNecessary(objectID string) bool {
115+
return strings.HasPrefix(objectID, "/sql/") && !strings.HasPrefix(objectID, "/sql/endpoints")
116+
}
117+
114118
func urlPathForObjectID(objectID string) string {
115-
if strings.HasPrefix(objectID, "/sql/") && !strings.HasPrefix(objectID, "/sql/endpoints") {
119+
if isDbsqlPermissionsWorkaroundNecessary(objectID) {
116120
// Permissions for SQLA entities are routed differently from the others.
117121
return "/preview/sql/permissions" + objectID[4:]
118122
}
@@ -121,7 +125,7 @@ func urlPathForObjectID(objectID string) string {
121125

122126
// Helper function to select the correct HTTP method depending on the object types.
123127
func (a PermissionsAPI) put(objectID string, objectACL AccessControlChangeList) error {
124-
if strings.HasPrefix(objectID, "/sql/") {
128+
if isDbsqlPermissionsWorkaroundNecessary(objectID) {
125129
// SQLA entities always have `CAN_MANAGE` permission for the calling user.
126130
me, err := scim.NewUsersAPI(a.context, a.client).Me()
127131
if err != nil {
@@ -131,15 +135,9 @@ func (a PermissionsAPI) put(objectID string, objectACL AccessControlChangeList)
131135
UserName: me.UserName,
132136
PermissionLevel: "CAN_MANAGE",
133137
})
134-
135-
if strings.HasPrefix(objectID, "/sql/endpoints/") {
136-
return a.client.Patch(a.context, urlPathForObjectID(objectID), objectACL)
137-
} else {
138-
// The rest of SQLA entities use HTTP POST for permission updates.
139-
return a.client.Post(a.context, urlPathForObjectID(objectID), objectACL, nil)
140-
}
138+
// SQLA entities use POST for permission updates.
139+
return a.client.Post(a.context, urlPathForObjectID(objectID), objectACL, nil)
141140
}
142-
143141
return a.client.Put(a.context, urlPathForObjectID(objectID), objectACL)
144142
}
145143

permissions/resource_permissions_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,18 +506,14 @@ func TestResourcePermissionsCreate_SQLA_Endpoint(t *testing.T) {
506506
Fixtures: []qa.HTTPFixture{
507507
me,
508508
{
509-
Method: http.MethodPatch,
509+
Method: "PUT",
510510
Resource: "/api/2.0/permissions/sql/endpoints/abc",
511511
ExpectedRequest: AccessControlChangeList{
512512
AccessControlList: []AccessControlChange{
513513
{
514514
UserName: TestingUser,
515515
PermissionLevel: "CAN_USE",
516516
},
517-
{
518-
UserName: TestingAdminUser,
519-
PermissionLevel: "CAN_MANAGE",
520-
},
521517
},
522518
},
523519
},
@@ -532,10 +528,6 @@ func TestResourcePermissionsCreate_SQLA_Endpoint(t *testing.T) {
532528
UserName: TestingUser,
533529
PermissionLevel: "CAN_USE",
534530
},
535-
{
536-
UserName: TestingAdminUser,
537-
PermissionLevel: "CAN_MANAGE",
538-
},
539531
},
540532
},
541533
},

sql/resource_sql_endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type SQLEndpoint struct {
2525
Name string `json:"name"`
2626
ClusterSize string `json:"cluster_size"`
2727
AutoStopMinutes int `json:"auto_stop_mins" tf:"default:120"`
28-
MinNumClusters int `json:"min_num_clusters,omitempty" tf:"default:1"`
28+
MinNumClusters int `json:"min_num_clusters,omitempty" tf:"default:1,suppress_diff"`
2929
MaxNumClusters int `json:"max_num_clusters,omitempty" tf:"default:1"`
3030
NumClusters int `json:"num_clusters,omitempty" tf:"default:1,suppress_diff"`
3131
EnablePhoton bool `json:"enable_photon" tf:"default:true"`

0 commit comments

Comments
 (0)