terraform: fix some test failures
This commit is contained in:
parent
61d275f475
commit
edd05f2aa2
|
@ -104,26 +104,31 @@ func (s *State) ModuleByPath(path []string) *ModuleState {
|
||||||
// returning their full paths. These paths can be used with ModuleByPath
|
// returning their full paths. These paths can be used with ModuleByPath
|
||||||
// to return the actual state.
|
// to return the actual state.
|
||||||
func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
|
func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
|
||||||
|
// direct keeps track of what direct children we have both in our config
|
||||||
|
// and in our state. childrenKeys keeps track of what isn't an orphan.
|
||||||
|
direct := make(map[string]struct{})
|
||||||
childrenKeys := make(map[string]struct{})
|
childrenKeys := make(map[string]struct{})
|
||||||
if c != nil {
|
if c != nil {
|
||||||
for _, m := range c.Modules {
|
for _, m := range c.Modules {
|
||||||
childrenKeys[m.Name] = struct{}{}
|
childrenKeys[m.Name] = struct{}{}
|
||||||
|
direct[m.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go over the direct children and find any that aren't in our keys.
|
// Go over the direct children and find any that aren't in our keys.
|
||||||
var orphans [][]string
|
var orphans [][]string
|
||||||
direct := make(map[string]struct{}, len(childrenKeys))
|
|
||||||
for _, m := range s.Children(path) {
|
for _, m := range s.Children(path) {
|
||||||
key := m.Path[len(m.Path)-1]
|
key := m.Path[len(m.Path)-1]
|
||||||
if _, ok := childrenKeys[key]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record that we found this key as a direct child. We use this
|
// Record that we found this key as a direct child. We use this
|
||||||
// later to find orphan nested modules.
|
// later to find orphan nested modules.
|
||||||
direct[key] = struct{}{}
|
direct[key] = struct{}{}
|
||||||
|
|
||||||
|
// If we have a direct child still in our config, it is not an orphan
|
||||||
|
if _, ok := childrenKeys[key]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
orphans = append(orphans, m.Path)
|
orphans = append(orphans, m.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +145,7 @@ func (s *State) ModuleOrphans(path []string, c *config.Config) [][]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have the direct child, then just skip it.
|
// If we have the direct child, then just skip it.
|
||||||
key := m.Path[len(m.Path)-1]
|
key := m.Path[len(m.Path)-2]
|
||||||
if _, ok := direct[key]; ok {
|
if _, ok := direct[key]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue