compare module by normalized path

The onld logic for locating comparing module paths no longer worked, and
we can simplify the comparison by using the addrs.ModuleInstance string.
This commit is contained in:
James Bardin 2018-05-17 16:19:25 -07:00 committed by Martin Atkins
parent ea727d9918
commit 3bd2293152

View File

@ -85,25 +85,13 @@ func (n *EvalDeleteModule) Eval(ctx EvalContext) (interface{}, error) {
state.prune() state.prune()
// find the module and delete it // find the module and delete it
Modules:
for i, m := range state.Modules { for i, m := range state.Modules {
// Since state is still using our old-style []string path representation, // Since state is still using our old-style []string path representation,
// comparison is a little awkward. This can be simplified once state // comparison is a little awkward. This can be simplified once state
// is updated to use addrs.ModuleInstance too. // is updated to use addrs.ModuleInstance too.
if len(m.Path) != len(n.Addr) { if normalizeModulePath(m.Path).String() != n.Addr.String() {
continue Modules continue
} }
for i, step := range n.Addr {
if step.InstanceKey != addrs.NoKey {
// Old-style state path can't have keys anyway, so this can
// never match.
continue Modules
}
if step.Name != m.Path[i] {
continue Modules
}
}
if !m.Empty() { if !m.Empty() {
// a targeted apply may leave module resources even without a config, // a targeted apply may leave module resources even without a config,
// so just log this and return. // so just log this and return.
@ -113,6 +101,5 @@ Modules:
state.Modules = append(state.Modules[:i], state.Modules[i+1:]...) state.Modules = append(state.Modules[:i], state.Modules[i+1:]...)
break break
} }
return nil, nil return nil, nil
} }