remove duplicates in Dependencies

duplicate entries could end up in "depends_on" in the state, which could
possible lead to erroneous state comparisons. Remove them when walking
the graph, and remove existing duplicates when pruning the state.
This commit is contained in:
James Bardin 2017-04-07 21:12:21 -04:00
parent 07ff095755
commit b45b6a5c20
3 changed files with 23 additions and 2 deletions

View File

@ -102,7 +102,7 @@ func (n *NodeAbstractResource) References() []string {
} }
} }
return result return uniqueStrings(result)
} }
// If we have state, that is our next source // If we have state, that is our next source

View File

@ -1163,6 +1163,8 @@ func (m *ModuleState) prune() {
delete(m.Outputs, k) delete(m.Outputs, k)
} }
} }
m.Dependencies = uniqueStrings(m.Dependencies)
} }
func (m *ModuleState) sort() { func (m *ModuleState) sort() {
@ -1526,8 +1528,9 @@ func (s *ResourceState) prune() {
i-- i--
} }
} }
s.Deposed = s.Deposed[:n] s.Deposed = s.Deposed[:n]
s.Dependencies = uniqueStrings(s.Dependencies)
} }
func (s *ResourceState) sort() { func (s *ResourceState) sort() {

View File

@ -1,6 +1,7 @@
package terraform package terraform
import ( import (
"sort"
"strings" "strings"
) )
@ -73,3 +74,20 @@ func strSliceContains(haystack []string, needle string) bool {
} }
return false return false
} }
// deduplicate a slice of strings
func uniqueStrings(s []string) []string {
if len(s) < 2 {
return s
}
sort.Strings(s)
result := make([]string, 1, len(s))
result[0] = s[0]
for i := 1; i < len(s); i++ {
if s[i] != result[len(result)-1] {
result = append(result, s[i])
}
}
return result
}