Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Bug Fixes

* Fix `ExactlyOneOf` in `databricks_app` ([#4946](https://github.com/databricks/terraform-provider-databricks/pull/4946))
* Fixed syncing of effective fields in plugin framework implementation of share resource ([#4969](https://github.com/databricks/terraform-provider-databricks/pull/4969))

### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,13 @@ func (r *ShareResource) syncEffectiveFields(ctx context.Context, plan, state Sha
stateObjects, _ := state.GetObjects(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we suppressing the error? Can this fail?

finalObjects := []sharing_tf.SharedDataObject_SdkV2{}
for i := range stateObjects {
mode.objectLevel(ctx, &stateObjects[i], planObjects[i])
finalObjects = append(finalObjects, stateObjects[i])
for j := range planObjects {
if stateObjects[i].Name == planObjects[j].Name {
mode.objectLevel(ctx, &stateObjects[i], planObjects[j])
finalObjects = append(finalObjects, stateObjects[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the plan as an object which is not in the state? It seems that we are ignoring it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we ignore it because in terraform we want to create the infra from the config

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit more what is what? I think I am mixing what stateObjects, planObjects and finalObjects are.
As it is, it feels that we are storing (state) a different set of objects that we are creating (plan).

break
}
}
}
state.SetObjects(ctx, finalObjects)
return state, d
Expand Down
142 changes: 142 additions & 0 deletions internal/providers/pluginfw/products/sharing/resource_share_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package sharing

import (
"context"
"testing"

"github.com/databricks/databricks-sdk-go/service/sharing"
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/converters"
"github.com/stretchr/testify/assert"
)

func TestShareSyncEffectiveFields(t *testing.T) {
shareName := "test-share-name"
ctx := context.Background()
shares := ShareResource{}

tests := []struct {
name string
planGoSDK sharing.ShareInfo
stateGoSDK sharing.ShareInfo
}{
{
name: "plan with less objects",
planGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{
{
Name: "obj-1",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-1"}}},
},
},
{
Name: "obj-3",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-3"}}},
},
},
},
},
stateGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{
{
Name: "obj-1",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-1"}}},
},
},
{
Name: "obj-2",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-2"}}},
},
},
{
Name: "obj-3",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-3"}}},
},
},
},
},
},
{
name: "plan with more objects",
planGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{
{
Name: "obj-1",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-1"}}},
},
},
{
Name: "obj-2",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-2"}}},
},
},
{
Name: "obj-3",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-3"}}},
},
},
},
},
stateGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{
{
Name: "obj-1",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-1"}}},
},
},
{
Name: "obj-3",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-3"}}},
},
},
},
},
},
{
name: "empty plan",
planGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{},
},
stateGoSDK: sharing.ShareInfo{
Name: shareName,
Objects: []sharing.SharedDataObject{
{
Name: "obj-1",
Partitions: []sharing.Partition{
{Values: []sharing.PartitionValue{{Value: "part-1"}}},
},
},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var planTFSDK ShareInfoExtended
diagnostics := converters.GoSdkToTfSdkStruct(ctx, tt.planGoSDK, &planTFSDK)
assert.False(t, diagnostics.HasError())

var stateTFSDK ShareInfoExtended
diagnostics = converters.GoSdkToTfSdkStruct(ctx, tt.stateGoSDK, &stateTFSDK)
assert.False(t, diagnostics.HasError())

_, diagnostics = shares.syncEffectiveFields(ctx, planTFSDK, stateTFSDK, effectiveFieldsActionRead{})
assert.False(t, diagnostics.HasError())
})
}
}
Loading