Skip to content

Commit 0d6c73c

Browse files
mgyuchtalexott
andauthored
Fix databricks_workspace_binding for existing resources using external-location or storage-credential (#4611)
## Changes Previously, the UC workspace binding API allowed users to specify `external-location` and `storage-credential` for the securable type in the [update securable workspace bindings API](https://docs.databricks.com/api/workspace/workspacebindings/updatebindings). This was changed to `external_location` and `storage_credential`. However, for users who created these bindings using the older names, those names were persisted in the `id` of the resource. As a result, the securable type is always updated to the older name, causing a permanent drift to appear. This PR changes the `Read()` method of `databricks_workspace_binding` to rewrite old-style securable types in this API to their new style names. The result is that there is no longer a difference in the `securable_type` attribute, which is the expected behavior. ## Tests Added a unit test to verify that an ID in the old style would be interpreted appropriately by the updated read method, resulting in no diff when the ID contains `external-location` and the `securable_type` is set to `external_location`. --------- Co-authored-by: Alex Ott <[email protected]>
1 parent 513ebfe commit 0d6c73c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Bug Fixes
1212

13+
* Fix `databricks_workspace_binding` for existing resources using `external-location` or `storage-credential` securable types ([#4611](https://github.com/databricks/terraform-provider-databricks/pull/4611)).
1314
* Suppress diff in `databricks_mlflow_experiment` name ([#4606](https://github.com/databricks/terraform-provider-databricks/pull/4606))
1415

1516
### Documentation

catalog/resource_workspace_binding.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ func ResourceWorkspaceBinding() common.Resource {
9191
return fmt.Errorf("incorrect binding id: %s. Correct format: <workspace_id>|<securable_type>|<securable_name>", d.Id())
9292
}
9393
securableName := parts[2]
94-
securableType := catalog.GetBindingsSecurableType(parts[1])
94+
// Previously, users could specify "external-location" and "storage-credential" as the securable type.
95+
// We need to convert them to "external_location" and "storage_credential" respectively.
96+
securableType := catalog.GetBindingsSecurableType(strings.Replace(parts[1], "-", "_", -1))
9597
workspaceId, err := strconv.ParseInt(parts[0], 10, 0)
9698
if err != nil {
9799
return fmt.Errorf("can't parse workspace_id: %w", err)

catalog/resource_workspace_binding_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,32 @@ func TestSecurableWorkspaceBindings_Delete(t *testing.T) {
243243
}.ApplyNoError(t)
244244
}
245245

246+
func TestWorkspaceBindingsRead_OldStyleSecurableType(t *testing.T) {
247+
qa.ResourceFixture{
248+
Fixtures: []qa.HTTPFixture{
249+
{
250+
Method: "GET",
251+
Resource: "/api/2.1/unity-catalog/bindings/external_location/my_catalog?",
252+
Response: catalog.WorkspaceBindingsResponse{
253+
Bindings: []catalog.WorkspaceBinding{
254+
{
255+
BindingType: catalog.WorkspaceBindingBindingTypeBindingTypeReadOnly,
256+
WorkspaceId: int64(1234567890101112),
257+
},
258+
},
259+
},
260+
},
261+
},
262+
Resource: ResourceWorkspaceBinding(),
263+
ID: "1234567890101112|external-location|my_catalog",
264+
Read: true,
265+
}.ApplyAndExpectData(t, map[string]any{
266+
"workspace_id": 1234567890101112,
267+
"securable_type": "external_location",
268+
"securable_name": "my_catalog",
269+
})
270+
}
271+
246272
func TestWorkspaceBindingsReadImport(t *testing.T) {
247273
qa.ResourceFixture{
248274
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)