|
|
|
|
@ -51,10 +51,10 @@ func (ms *Module) ResourceInstance(addr addrs.ResourceInstance) *ResourceInstanc
|
|
|
|
|
return rs.Instance(addr.Key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetResourceMeta updates the resource-level metadata for the resource
|
|
|
|
|
// SetResourceProvider updates the resource-level metadata for the resource
|
|
|
|
|
// with the given address, creating the resource state for it if it doesn't
|
|
|
|
|
// already exist.
|
|
|
|
|
func (ms *Module) SetResourceMeta(addr addrs.Resource, eachMode EachMode, provider addrs.AbsProviderConfig) {
|
|
|
|
|
func (ms *Module) SetResourceProvider(addr addrs.Resource, provider addrs.AbsProviderConfig) {
|
|
|
|
|
rs := ms.Resource(addr)
|
|
|
|
|
if rs == nil {
|
|
|
|
|
rs = &Resource{
|
|
|
|
|
@ -64,7 +64,6 @@ func (ms *Module) SetResourceMeta(addr addrs.Resource, eachMode EachMode, provid
|
|
|
|
|
ms.Resources[addr.String()] = rs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rs.EachMode = eachMode
|
|
|
|
|
rs.ProviderConfig = provider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -97,9 +96,7 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|
|
|
|
if obj == nil && rs != nil {
|
|
|
|
|
// does the resource have any other objects?
|
|
|
|
|
// if not then delete the whole resource
|
|
|
|
|
// When deleting the resource, ensure that its EachMode is NoEach,
|
|
|
|
|
// as a resource with EachList or EachMap can have 0 instances and be valid
|
|
|
|
|
if rs.EachMode == NoEach && len(rs.Instances) == 0 {
|
|
|
|
|
if len(rs.Instances) == 0 {
|
|
|
|
|
delete(ms.Resources, addr.Resource.String())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
@ -115,7 +112,7 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|
|
|
|
// If we have no objects at all then we'll clean up.
|
|
|
|
|
delete(rs.Instances, addr.Key)
|
|
|
|
|
// Delete the resource if it has no instances, but only if NoEach
|
|
|
|
|
if rs.EachMode == NoEach && len(rs.Instances) == 0 {
|
|
|
|
|
if len(rs.Instances) == 0 {
|
|
|
|
|
delete(ms.Resources, addr.Resource.String())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
@ -125,7 +122,7 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|
|
|
|
}
|
|
|
|
|
if rs == nil && obj != nil {
|
|
|
|
|
// We don't have have a resource so make one, which is a side effect of setResourceMeta
|
|
|
|
|
ms.SetResourceMeta(addr.Resource, eachModeForInstanceKey(addr.Key), provider)
|
|
|
|
|
ms.SetResourceProvider(addr.Resource, provider)
|
|
|
|
|
// now we have a resource! so update the rs value to point to it
|
|
|
|
|
rs = ms.Resource(addr.Resource)
|
|
|
|
|
}
|
|
|
|
|
@ -134,8 +131,8 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|
|
|
|
if is == nil {
|
|
|
|
|
// if we don't have a resource, create one and add to the instances
|
|
|
|
|
is = rs.CreateInstance(addr.Key)
|
|
|
|
|
// update the resource meta because we have a new instance, so EachMode may have changed
|
|
|
|
|
ms.SetResourceMeta(addr.Resource, eachModeForInstanceKey(addr.Key), provider)
|
|
|
|
|
// update the resource meta because we have a new
|
|
|
|
|
ms.SetResourceProvider(addr.Resource, provider)
|
|
|
|
|
}
|
|
|
|
|
// Update the resource's ProviderConfig, in case the provider has updated
|
|
|
|
|
rs.ProviderConfig = provider
|
|
|
|
|
@ -159,7 +156,7 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|
|
|
|
// the instance is left with no objects after this operation then it will
|
|
|
|
|
// be removed from its containing resource altogether.
|
|
|
|
|
func (ms *Module) SetResourceInstanceDeposed(addr addrs.ResourceInstance, key DeposedKey, obj *ResourceInstanceObjectSrc, provider addrs.AbsProviderConfig) {
|
|
|
|
|
ms.SetResourceMeta(addr.Resource, eachModeForInstanceKey(addr.Key), provider)
|
|
|
|
|
ms.SetResourceProvider(addr.Resource, provider)
|
|
|
|
|
|
|
|
|
|
rs := ms.Resource(addr.Resource)
|
|
|
|
|
is := rs.EnsureInstance(addr.Key)
|
|
|
|
|
@ -173,7 +170,7 @@ func (ms *Module) SetResourceInstanceDeposed(addr addrs.ResourceInstance, key De
|
|
|
|
|
// 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 {
|
|
|
|
|
if 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.
|
|
|
|
|
@ -190,7 +187,7 @@ func (ms *Module) ForgetResourceInstanceAll(addr addrs.ResourceInstance) {
|
|
|
|
|
}
|
|
|
|
|
delete(rs.Instances, addr.Key)
|
|
|
|
|
|
|
|
|
|
if rs.EachMode == NoEach && len(rs.Instances) == 0 {
|
|
|
|
|
if 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.
|
|
|
|
|
@ -215,7 +212,7 @@ func (ms *Module) ForgetResourceInstanceDeposed(addr addrs.ResourceInstance, key
|
|
|
|
|
// 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 {
|
|
|
|
|
if 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.
|
|
|
|
|
|