@@ -254,6 +254,22 @@ func (p *shadowResourceProviderReal) ReadDataDiff(
254254 return result , err
255255}
256256
257+ func (p * shadowResourceProviderReal ) ReadDataApply (
258+ info * InstanceInfo ,
259+ diff * InstanceDiff ) (* InstanceState , error ) {
260+ // Thse have to be copied before the call since call can modify
261+ diffCopy := diff .DeepCopy ()
262+
263+ result , err := p .ResourceProvider .ReadDataApply (info , diff )
264+ p .Shared .ReadDataApply .SetValue (info .uniqueId (), & shadowResourceProviderReadDataApply {
265+ Diff : diffCopy ,
266+ Result : result .DeepCopy (),
267+ ResultErr : err ,
268+ })
269+
270+ return result , err
271+ }
272+
257273// shadowResourceProviderShadow is the shadow resource provider. Function
258274// calls never affect real resources. This is paired with the "real" side
259275// which must be called properly to enable recording.
@@ -282,6 +298,7 @@ type shadowResourceProviderShared struct {
282298 Refresh shadow.KeyedValue
283299 ValidateDataSource shadow.KeyedValue
284300 ReadDataDiff shadow.KeyedValue
301+ ReadDataApply shadow.KeyedValue
285302}
286303
287304func (p * shadowResourceProviderShared ) Close () error {
@@ -679,6 +696,42 @@ func (p *shadowResourceProviderShadow) ReadDataDiff(
679696 return result .Result , result .ResultErr
680697}
681698
699+ func (p * shadowResourceProviderShadow ) ReadDataApply (
700+ info * InstanceInfo ,
701+ d * InstanceDiff ) (* InstanceState , error ) {
702+ // Unique key
703+ key := info .uniqueId ()
704+ raw := p .Shared .ReadDataApply .Value (key )
705+ if raw == nil {
706+ p .ErrorLock .Lock ()
707+ defer p .ErrorLock .Unlock ()
708+ p .Error = multierror .Append (p .Error , fmt .Errorf (
709+ "Unknown 'ReadDataApply' call for %q:\n \n %#v" ,
710+ key , d ))
711+ return nil , nil
712+ }
713+
714+ result , ok := raw .(* shadowResourceProviderReadDataApply )
715+ if ! ok {
716+ p .ErrorLock .Lock ()
717+ defer p .ErrorLock .Unlock ()
718+ p .Error = multierror .Append (p .Error , fmt .Errorf (
719+ "Unknown 'ReadDataApply' shadow value: %#v" , raw ))
720+ return nil , nil
721+ }
722+
723+ // Compare the parameters, which should be identical
724+ if ! d .Equal (result .Diff ) {
725+ p .ErrorLock .Lock ()
726+ p .Error = multierror .Append (p .Error , fmt .Errorf (
727+ "ReadDataApply: unequal diffs (real, then shadow):\n \n %#v\n \n %#v" ,
728+ result .Diff , d ))
729+ p .ErrorLock .Unlock ()
730+ }
731+
732+ return result .Result , result .ResultErr
733+ }
734+
682735// TODO
683736// TODO
684737// TODO
@@ -689,12 +742,6 @@ func (p *shadowResourceProviderShadow) ImportState(info *InstanceInfo, id string
689742 return nil , nil
690743}
691744
692- func (p * shadowResourceProviderShadow ) ReadDataApply (
693- info * InstanceInfo ,
694- d * InstanceDiff ) (* InstanceState , error ) {
695- return nil , nil
696- }
697-
698745// The structs for the various function calls are put below. These structs
699746// are used to carry call information across the real/shadow boundaries.
700747
@@ -764,3 +811,9 @@ type shadowResourceProviderReadDataDiff struct {
764811 Result * InstanceDiff
765812 ResultErr error
766813}
814+
815+ type shadowResourceProviderReadDataApply struct {
816+ Diff * InstanceDiff
817+ Result * InstanceState
818+ ResultErr error
819+ }
0 commit comments