TargetContains improvements

Simplify Module.TargetContains

Handle the case of a keyed instance address in
ModuleInstance.TargetContains.
This commit is contained in:
James Bardin 2020-03-12 18:14:44 -04:00
parent 076c540076
commit bf91bff2c8
2 changed files with 11 additions and 11 deletions

View File

@ -71,17 +71,7 @@ func (m Module) TargetContains(other Targetable) bool {
return true
case ModuleInstance:
if len(to) < len(m) {
return false
}
for i, ourStep := range m {
otherStep := to[i]
// This is where ModuleInstance differs from Module
if ourStep != otherStep.Name {
return false
}
}
return true
return m.TargetContains(to.Module())
case AbsResource:
return m.TargetContains(to.Module)

View File

@ -391,6 +391,16 @@ func (m ModuleInstance) TargetContains(other Targetable) bool {
// Other is contained if its steps match for the length of our own path.
for i, ourStep := range m {
otherStep := to[i]
// We can't contain an entire module if we have a specific instance
// key. The case of NoKey is OK because this address is either
// meant to address an unexpanded module, or a single instance of
// that module, and both of those are a covered in-full by the
// Module address.
if ourStep.InstanceKey != NoKey {
return false
}
if ourStep.Name != otherStep {
return false
}