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:
parent
07ff095755
commit
b45b6a5c20
|
@ -102,7 +102,7 @@ func (n *NodeAbstractResource) References() []string {
|
|||
}
|
||||
}
|
||||
|
||||
return result
|
||||
return uniqueStrings(result)
|
||||
}
|
||||
|
||||
// If we have state, that is our next source
|
||||
|
|
|
@ -1163,6 +1163,8 @@ func (m *ModuleState) prune() {
|
|||
delete(m.Outputs, k)
|
||||
}
|
||||
}
|
||||
|
||||
m.Dependencies = uniqueStrings(m.Dependencies)
|
||||
}
|
||||
|
||||
func (m *ModuleState) sort() {
|
||||
|
@ -1526,8 +1528,9 @@ func (s *ResourceState) prune() {
|
|||
i--
|
||||
}
|
||||
}
|
||||
|
||||
s.Deposed = s.Deposed[:n]
|
||||
|
||||
s.Dependencies = uniqueStrings(s.Dependencies)
|
||||
}
|
||||
|
||||
func (s *ResourceState) sort() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -73,3 +74,20 @@ func strSliceContains(haystack []string, needle string) bool {
|
|||
}
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue