hcl2 inspect: sort variables to have a consistent output
This commit is contained in:
parent
a25f057984
commit
bdf198594e
|
@ -2,6 +2,7 @@ package hcl2template
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
|
@ -460,12 +461,18 @@ func (p *PackerConfig) EvaluateExpression(line string) (out string, exit bool, d
|
|||
func (p *PackerConfig) printVariables() string {
|
||||
out := &strings.Builder{}
|
||||
out.WriteString("> input-variables:\n\n")
|
||||
for _, v := range p.InputVariables {
|
||||
keys := p.InputVariables.Keys()
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
v := p.InputVariables[key]
|
||||
val, _ := v.Value()
|
||||
fmt.Fprintf(out, "var.%s: %q\n", v.Name, PrintableCtyValue(val))
|
||||
}
|
||||
out.WriteString("\n> local-variables:\n\n")
|
||||
for _, v := range p.LocalVariables {
|
||||
keys = p.LocalVariables.Keys()
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
v := p.LocalVariables[key]
|
||||
val, _ := v.Value()
|
||||
fmt.Fprintf(out, "local.%s: %q\n", v.Name, PrintableCtyValue(val))
|
||||
}
|
||||
|
|
|
@ -84,6 +84,14 @@ func (v *Variable) Value() (cty.Value, *hcl.Diagnostic) {
|
|||
|
||||
type Variables map[string]*Variable
|
||||
|
||||
func (variables Variables) Keys() []string {
|
||||
keys := make([]string, 0, len(variables))
|
||||
for key := range variables {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func (variables Variables) Values() (map[string]cty.Value, hcl.Diagnostics) {
|
||||
res := map[string]cty.Value{}
|
||||
var diags hcl.Diagnostics
|
||||
|
|
Loading…
Reference in New Issue