Add a new method cause doing things in module is weird
This commit is contained in:
parent
3b4382082d
commit
87fdcd0064
|
@ -102,7 +102,7 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|||
return
|
||||
}
|
||||
// check for an existing resource, now that we've ensured that rs.Instances is more than 0/not nil
|
||||
is := rs.Instances[addr.Key]
|
||||
is := rs.Instance(addr.Key)
|
||||
if is == nil {
|
||||
// if there is no instance, but the resource exists and has other instances,
|
||||
// be chill, just return
|
||||
|
@ -130,14 +130,12 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R
|
|||
rs = ms.Resource(addr.Resource)
|
||||
}
|
||||
// Get our instance from the resource; it could be there or not at this point
|
||||
is := rs.Instances[addr.Key]
|
||||
is := rs.Instance(addr.Key)
|
||||
if is == nil {
|
||||
// if we don't have a resource, create one and add to the instances
|
||||
is = NewResourceInstance()
|
||||
rs.Instances[addr.Key] = is
|
||||
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)
|
||||
|
||||
}
|
||||
is.Current = obj
|
||||
}
|
||||
|
|
|
@ -39,6 +39,13 @@ func (rs *Resource) Instance(key addrs.InstanceKey) *ResourceInstance {
|
|||
return rs.Instances[key]
|
||||
}
|
||||
|
||||
// CreateInstance creates an instance and adds it to the resource
|
||||
func (rs *Resource) CreateInstance(key addrs.InstanceKey) *ResourceInstance {
|
||||
is := NewResourceInstance()
|
||||
rs.Instances[key] = is
|
||||
return is
|
||||
}
|
||||
|
||||
// EnsureInstance returns the state for the instance with the given key,
|
||||
// creating a new empty state for it if one doesn't already exist.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue