code: func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *ResourceInstanceObjectSrc, provider addrs.AbsProviderConfig) {
  	ms.SetResourceMeta(addr.Resource, eachModeForInstanceKey(addr.Key), provider)
  
  	rs := ms.Resource(addr.Resource)
  	is := rs.EnsureInstance(addr.Key)
  
  	is.Current = obj
  
  	if !is.HasObjects() {
  		// If we have no objects at all then we'll clean up.
  		delete(rs.Instances, addr.Key)
  	}
  	if rs.EachMode == NoEach && len(rs.Instances) == 0 {
  		// Also clean up if we only expect to have one instance anyway
  		// and there are none. We leave the resource behind if an each mode
  		// is active because an empty list or map of instances is a valid state.
  		delete(ms.Resources, addr.Resource.String())
  	}
  }
docs: // SetResourceInstanceCurrent saves the given instance object as the current
  // generation of the resource instance with the given address, simulataneously
  // updating the recorded provider configuration address, dependencies, and
  // resource EachMode.
  //
  // Any existing current instance object for the given resource is overwritten.
  // Set obj to nil to remove the primary generation object altogether. If there
  // are no deposed objects then the instance will be removed altogether.
  //
  // The provider address and "each mode" are resource-wide settings and so they
  // are updated for all other instances of the same resource as a side-effect of
  // this call.