Skip to content

Commit

Permalink
Sort map keys to get stable outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Feb 4, 2018
1 parent 20fabd6 commit 54f8baa
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tfschema/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"sort"
"strconv"

"github.com/hashicorp/terraform/config/configschema"
Expand Down Expand Up @@ -79,7 +80,16 @@ func (b *Block) renderAttributes() (string, error) {
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)

table.SetHeader([]string{"attribute", "type", "required", "optional", "computed", "sensitive"})
for k, v := range b.Attributes {

// sort map keys
keys := []string{}
for k := range b.Attributes {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
v := b.Attributes[k]
typeName, err := v.Type.Name()
if err != nil {
return "", err
Expand Down Expand Up @@ -107,7 +117,16 @@ func (b *Block) renderBlockTypes() (string, error) {
}

buf := new(bytes.Buffer)
for k, v := range b.BlockTypes {

// sort map keys
keys := []string{}
for k := range b.BlockTypes {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
v := b.BlockTypes[k]
blockType := fmt.Sprintf("\nblock_type: %s, nesting: %s, min_items: %d, max_items: %d\n", k, v.Nesting, v.MinItems, v.MaxItems)
buf.WriteString(blockType)

Expand Down

0 comments on commit 54f8baa

Please sign in to comment.