mirror of
https://github.com/hashicorp/terraform.git
synced 2026-05-28 04:03:27 -04:00
cmd/modules: Ensure modules are sorted by reference key (#36268)
This commit is contained in:
parent
fa27595fe3
commit
908828be8a
4 changed files with 21 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ package views
|
|||
import (
|
||||
encJson "encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/arguments"
|
||||
"github.com/hashicorp/terraform/internal/moduleref"
|
||||
|
|
@ -44,6 +45,10 @@ func (v *ModulesHuman) Display(manifest moduleref.Manifest) int {
|
|||
return 0
|
||||
}
|
||||
printRoot := treeprint.New()
|
||||
|
||||
// ensure output is deterministic
|
||||
sort.Sort(manifest.Records)
|
||||
|
||||
populateTreeNode(printRoot, &moduleref.Record{
|
||||
Children: manifest.Records,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ type Record struct {
|
|||
Source addrs.ModuleSource
|
||||
Version *version.Version
|
||||
VersionConstraints version.Constraints
|
||||
Children []*Record
|
||||
Children Records
|
||||
}
|
||||
|
||||
// ModuleRecordManifest is the view implementation of module entries declared
|
||||
// in configuration
|
||||
type Manifest struct {
|
||||
FormatVersion string
|
||||
Records []*Record
|
||||
Records Records
|
||||
}
|
||||
|
||||
func (m *Manifest) addModuleEntry(entry *Record) {
|
||||
|
|
@ -34,3 +34,15 @@ func (m *Manifest) addModuleEntry(entry *Record) {
|
|||
func (r *Record) addChild(child *Record) {
|
||||
r.Children = append(r.Children, child)
|
||||
}
|
||||
|
||||
type Records []*Record
|
||||
|
||||
func (r Records) Len() int {
|
||||
return len(r)
|
||||
}
|
||||
func (r Records) Less(i, j int) bool {
|
||||
return r[i].Key < r[j].Key
|
||||
}
|
||||
func (r Records) Swap(i, j int) {
|
||||
r[i], r[j] = r[j], r[i]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func NewResolver(internalManifest modsdir.Manifest) *Resolver {
|
|||
internalManifest: internalManifestCopy,
|
||||
manifest: &Manifest{
|
||||
FormatVersion: FormatVersion,
|
||||
Records: []*Record{},
|
||||
Records: Records{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ func TestResolver_ResolveNestedChildren(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func countAndListSources(records []*Record) (count int, sources []string) {
|
||||
func countAndListSources(records Records) (count int, sources []string) {
|
||||
for _, record := range records {
|
||||
sources = append(sources, record.Source.String())
|
||||
count++
|
||||
|
|
|
|||
Loading…
Reference in a new issue