// SetResourceInstanceCurrent saves the given instance object as the current
// generation of the resource instance with the given address, simultaneously
// updating the recorded provider configuration address and dependencies.
//
// 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 is a resource-wide setting and is updated for all other
// instances of the same resource as a side-effect of this call.
SetResourceInstanceCurrent saves the given instance object as the current
generation of the resource instance with the given address, simultaneously
updating the recorded provider configuration address and dependencies.

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 is a resource-wide setting and is updated for all other
instances of the same resource as a side-effect of this call.
// SetResourceInstanceCurrent saves the given instance object as the current // generation of the resource instance with the given address simultaneously // updating the recorded provider configuration address and dependencies . // // 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 is a resource - wide setting and is updated for all other // instances of the same resource as a side - effect of this call .
func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *ResourceInstanceObjectSrc, provider addrs.AbsProviderConfig) {
	rs := ms.Resource(addr.Resource)
	if obj == nil && rs == nil {
		return
	}
	if obj == nil && rs != nil {
		if len(rs.Instances) == 0 {
			delete(ms.Resources, addr.Resource.String())
			return
		}
		is := rs.Instance(addr.Key)
		if is == nil {
			return
		}
		is.Current = obj
		if !is.HasObjects() {
			delete(rs.Instances, addr.Key)
			if len(rs.Instances) == 0 {
				delete(ms.Resources, addr.Resource.String())
				return
			}
		}
		return
	}
	if rs == nil && obj != nil {
		ms.SetResourceProvider(addr.Resource, provider)
		rs = ms.Resource(addr.Resource)
	}
	is := rs.Instance(addr.Key)
	if is == nil {
		is = rs.CreateInstance(addr.Key)
		ms.SetResourceProvider(addr.Resource, provider)
	}
	rs.ProviderConfig = provider
	is.Current = obj
}
func ( ms * Module ) SetResourceInstanceCurrent ( addr addrs . ResourceInstance , obj * ResourceInstanceObjectSrc , provider addrs . AbsProviderConfig ) { rs := ms . Resource ( addr . Resource ) if obj == nil && rs == nil { return } if obj == nil && rs != nil { if len ( rs . Instances ) == 0 { delete ( ms . Resources , addr . Resource . String ( ) ) return } is := rs . Instance ( addr . Key ) if is == nil { return } is . Current = obj if ! is . HasObjects ( ) { delete ( rs . Instances , addr . Key ) if len ( rs . Instances ) == 0 { delete ( ms . Resources , addr . Resource . String ( ) ) return } } return } if rs == nil && obj != nil { ms . SetResourceProvider ( addr . Resource , provider ) rs = ms . Resource ( addr . Resource ) } is := rs . Instance ( addr . Key ) if is == nil { is = rs . CreateInstance ( addr . Key ) ms . SetResourceProvider ( addr . Resource , provider ) } rs . ProviderConfig = provider is . Current = obj }
SetResourceInstanceCurrent saves the given instance object as the current
generation of the resource instance with the given address, simultaneously
updating the recorded provider configuration address and dependencies.
SetResourceInstanceCurrent saves the given instance object as the current generation of the resource instance with the given address simultaneously updating the recorded provider configuration address and dependencies .
// if the resource is nil and the object is nil, don't do anything! // you'll probably just cause issues // does the resource have any other objects? // if not then delete the whole resource // check for an existing resource, now that we've ensured that rs.Instances is more than 0/not nil // if there is no instance on the resource with this address and obj is nil, return and change nothing // if we have an instance, update the current // If we have no objects at all then we'll clean up. // Delete the resource if it has no instances, but only if NoEach // Nothing more to do here, so return! // We don't have have a resource so make one, which is a side effect of setResourceMeta // now we have a resource! so update the rs value to point to it // Get our instance from the resource; it could be there or not at this point // if we don't have a resource, create one and add to the instances // update the resource meta because we have a new // Update the resource's ProviderConfig, in case the provider has updated