GetConfigResourceChanges from plans
In order to find any changes related to a particular configuration address, we need a new method to get changes to all possible instances.
This commit is contained in:
parent
f8907b9213
commit
18ca98a064
|
@ -52,6 +52,22 @@ func (c *Changes) ResourceInstance(addr addrs.AbsResourceInstance) *ResourceInst
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigResourceInstances returns the planned change for the current objects
|
||||||
|
// of the resource instances of the given address, if any. Returns nil if no
|
||||||
|
// changes are planned.
|
||||||
|
func (c *Changes) ConfigResourceInstances(addr addrs.ConfigResource) []*ResourceInstanceChangeSrc {
|
||||||
|
var changes []*ResourceInstanceChangeSrc
|
||||||
|
for _, rc := range c.Resources {
|
||||||
|
resAddr := rc.Addr.ContainingResource().Config()
|
||||||
|
if resAddr.Equal(addr) && rc.DeposedKey == states.NotDeposed {
|
||||||
|
changes = append(changes, rc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceInstanceDeposed returns the plan change of a deposed object of
|
// ResourceInstanceDeposed returns the plan change of a deposed object of
|
||||||
|
|
|
@ -62,6 +62,29 @@ func (cs *ChangesSync) GetResourceInstanceChange(addr addrs.AbsResourceInstance,
|
||||||
panic(fmt.Sprintf("unsupported generation value %#v", gen))
|
panic(fmt.Sprintf("unsupported generation value %#v", gen))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfigResourceChanges searched the set of resource instance
|
||||||
|
// changes and returns all changes related to a given configuration address.
|
||||||
|
// This is be used to find possible changes related to a configuration
|
||||||
|
// reference.
|
||||||
|
//
|
||||||
|
// If no such changes exist, nil is returned.
|
||||||
|
//
|
||||||
|
// The returned objects are a deep copy of the change recorded in the plan, so
|
||||||
|
// callers may mutate them although it's generally better (less confusing) to
|
||||||
|
// treat planned changes as immutable after they've been initially constructed.
|
||||||
|
func (cs *ChangesSync) GetConfigResourceChanges(addr addrs.ConfigResource) []*ResourceInstanceChangeSrc {
|
||||||
|
if cs == nil {
|
||||||
|
panic("GetConfigResourceChanges on nil ChangesSync")
|
||||||
|
}
|
||||||
|
cs.lock.Lock()
|
||||||
|
defer cs.lock.Unlock()
|
||||||
|
var changes []*ResourceInstanceChangeSrc
|
||||||
|
for _, c := range cs.changes.ConfigResourceInstances(addr) {
|
||||||
|
changes = append(changes, c.DeepCopy())
|
||||||
|
}
|
||||||
|
return changes
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveResourceInstanceChange searches the set of resource instance changes
|
// RemoveResourceInstanceChange searches the set of resource instance changes
|
||||||
// for one matching the given address and generation, and removes it from the
|
// for one matching the given address and generation, and removes it from the
|
||||||
// set if it exists.
|
// set if it exists.
|
||||||
|
|
Loading…
Reference in New Issue