@@ -439,21 +439,30 @@ func (effectiveFieldsActionRead) objectLevel(ctx context.Context, state *sharing
439
439
state .SyncFieldsDuringRead (ctx , plan )
440
440
}
441
441
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 ) {
443
452
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 )
447
456
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 ])
453
462
break
454
463
}
455
464
}
456
465
}
457
- state .SetObjects (ctx , finalObjects )
458
- return state , d
466
+ newState .SetObjects (ctx , finalObjects )
467
+ return newState , d
459
468
}
0 commit comments