Skip to content

Commit d4d3422

Browse files
authored
[Fix] Share Reordering Issue (#4481)
## Changes <!-- Summary of your changes that are easy to understand --> This PR fixes an issue where reordering objects in a (pluginfw) Share would fail unless other changes were made to the objects. The bug caused the new order to be ignored if no additional modifications were present. With this fix, reordering now correctly updates the Share, whether or not other changes are made. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework Co-authored-by: Omer Lachish <[email protected]>
1 parent 83024cd commit d4d3422

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Increase `databricks_library` timeout from 15m to 30m.
99

1010
### Bug Fixes
11+
* Fixed an issue where reordering objects in a (pluginfw) Share wouldn’t update properly unless other changes were made ([#4481](https://github.com/databricks/terraform-provider-databricks/pull/4481)).
1112

1213
### Documentation
1314

internal/providers/pluginfw/products/sharing/resource_acc_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,35 @@ func TestUcAccUpdateShareAddObject(t *testing.T) {
202202
}`,
203203
})
204204
}
205+
206+
func TestUcAccUpdateShareReorderObject(t *testing.T) {
207+
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
208+
Template: preTestTemplate + preTestTemplateUpdate +
209+
`resource "databricks_share_pluginframework" "myshare" {
210+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
211+
owner = "account users"
212+
object {
213+
name = databricks_table.mytable.id
214+
data_object_type = "TABLE"
215+
}
216+
object {
217+
name = databricks_table.mytable_3.id
218+
data_object_type = "TABLE"
219+
}
220+
}`,
221+
}, acceptance.Step{
222+
Template: preTestTemplate + preTestTemplateUpdate +
223+
`resource "databricks_share_pluginframework" "myshare" {
224+
name = "{var.STICKY_RANDOM}-terraform-delta-share"
225+
owner = "account users"
226+
object {
227+
name = databricks_table.mytable_3.id
228+
data_object_type = "TABLE"
229+
}
230+
object {
231+
name = databricks_table.mytable.id
232+
data_object_type = "TABLE"
233+
}
234+
}`,
235+
})
236+
}

internal/providers/pluginfw/products/sharing/resource_share.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,
346346
}
347347
}
348348

349+
upToDateShareInfo := currentShareInfo
349350
if len(changes) > 0 {
350351
// if there are any other changes, update the share with the changes
351-
updatedShareInfo, err := client.Shares.Update(ctx, sharing.UpdateShare{
352+
upToDateShareInfo, err = client.Shares.Update(ctx, sharing.UpdateShare{
352353
Name: plan.Name.ValueString(),
353354
Updates: changes,
354355
})
@@ -371,11 +372,12 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,
371372
}
372373
}
373374

374-
matchOrder(updatedShareInfo.Objects, planGoSDK.Objects, func(obj sharing.SharedDataObject) string { return obj.Name })
375-
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, updatedShareInfo, &state)...)
376-
if resp.Diagnostics.HasError() {
377-
return
378-
}
375+
}
376+
377+
matchOrder(upToDateShareInfo.Objects, planGoSDK.Objects, func(obj sharing.SharedDataObject) string { return obj.Name })
378+
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, upToDateShareInfo, &state)...)
379+
if resp.Diagnostics.HasError() {
380+
return
379381
}
380382

381383
state, d := r.syncEffectiveFields(ctx, plan, state, effectiveFieldsActionCreateOrUpdate{})

0 commit comments

Comments
 (0)