Skip to content

Commit 55e1a33

Browse files
committed
-
1 parent 34182f2 commit 55e1a33

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,21 +439,30 @@ func (effectiveFieldsActionRead) objectLevel(ctx context.Context, state *sharing
439439
state.SyncFieldsDuringRead(ctx, plan)
440440
}
441441

442-
func (r *ShareResource) syncEffectiveFields(ctx context.Context, plan, state ShareInfoExtended, mode effectiveFieldsAction) (ShareInfoExtended, diag.Diagnostics) {
442+
// syncEffectiveFields syncs the effective fields between existingState and newState
443+
// and returns the newState
444+
//
445+
// existingState: infrastructure values that are recorded in the existing terraform state.
446+
// newState: latest infrastructure values that are returned by the CRUD API calls.
447+
//
448+
// HCL config is compared with this newState to determine what changes are to be made
449+
// to the infrastructure and then the newState values are recorded in the terraform state.
450+
// Hence we ignore the values in existingState which are not present in newState.
451+
func (r *ShareResource) syncEffectiveFields(ctx context.Context, existingState, newState ShareInfoExtended, mode effectiveFieldsAction) (ShareInfoExtended, diag.Diagnostics) {
443452
var d diag.Diagnostics
444-
mode.resourceLevel(ctx, &state, plan.ShareInfo_SdkV2)
445-
planObjects, _ := plan.GetObjects(ctx)
446-
stateObjects, _ := state.GetObjects(ctx)
453+
mode.resourceLevel(ctx, &newState, existingState.ShareInfo_SdkV2)
454+
existingStateObjects, _ := existingState.GetObjects(ctx)
455+
newStateObjects, _ := newState.GetObjects(ctx)
447456
finalObjects := []sharing_tf.SharedDataObject_SdkV2{}
448-
for i := range stateObjects {
449-
for j := range planObjects {
450-
if stateObjects[i].Name == planObjects[j].Name {
451-
mode.objectLevel(ctx, &stateObjects[i], planObjects[j])
452-
finalObjects = append(finalObjects, stateObjects[i])
457+
for i := range newStateObjects {
458+
for j := range existingStateObjects {
459+
if newStateObjects[i].Name == existingStateObjects[j].Name {
460+
mode.objectLevel(ctx, &newStateObjects[i], existingStateObjects[j])
461+
finalObjects = append(finalObjects, newStateObjects[i])
453462
break
454463
}
455464
}
456465
}
457-
state.SetObjects(ctx, finalObjects)
458-
return state, d
466+
newState.SetObjects(ctx, finalObjects)
467+
return newState, d
459468
}

0 commit comments

Comments
 (0)