unkeyed target ModulesInstance can be Modules
If the last step in a module target is an unkeyed instance, and it's being compared against keyed instances, we have to assume it was intended to be used as a Module rather than a ModuleInstance.
This commit is contained in:
parent
299aa31b43
commit
b861f5a4d7
|
@ -414,9 +414,26 @@ func (m ModuleInstance) TargetContains(other Targetable) bool {
|
|||
}
|
||||
for i, ourStep := range m {
|
||||
otherStep := to[i]
|
||||
if ourStep != otherStep {
|
||||
|
||||
if ourStep.Name != otherStep.Name {
|
||||
return false
|
||||
}
|
||||
|
||||
// if this is our last step, because all targets are parsed as
|
||||
// instances, this may be a ModuleInstance intended to be used as a
|
||||
// Module.
|
||||
if i == len(m)-1 {
|
||||
if ourStep.InstanceKey == NoKey {
|
||||
// If the other step is a keyed instance, then we contain that
|
||||
// step, and if it isn't it's a match, which is true either way
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if ourStep.InstanceKey != otherStep.InstanceKey {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
return true
|
||||
|
||||
|
|
|
@ -20,13 +20,6 @@ func TestTargetContains(t *testing.T) {
|
|||
mustParseTarget("module.foo"),
|
||||
true,
|
||||
},
|
||||
{
|
||||
// module.foo is an unkeyed module instance here, so it cannot
|
||||
// contain another instance
|
||||
mustParseTarget("module.foo"),
|
||||
mustParseTarget("module.foo[0]"),
|
||||
false,
|
||||
},
|
||||
{
|
||||
RootModuleInstance,
|
||||
mustParseTarget("module.foo"),
|
||||
|
@ -99,6 +92,11 @@ func TestTargetContains(t *testing.T) {
|
|||
mustParseTarget("module.bar.test_resource.foo[0]"),
|
||||
true,
|
||||
},
|
||||
{
|
||||
mustParseTarget("module.bax"),
|
||||
mustParseTarget("module.bax[0].test_resource.foo[0]"),
|
||||
true,
|
||||
},
|
||||
|
||||
// Config paths, while never returned from parsing a target, must still
|
||||
// be targetable
|
||||
|
|
Loading…
Reference in New Issue