Skip to content

Commit

Permalink
Merge pull request #116 from terraform-providers/jbardin/compose-reso…
Browse files Browse the repository at this point in the history
…urce-id-order

Sort ResourceID.Path keys for consistent output
  • Loading branch information
stack72 authored Jun 21, 2017
2 parents 5a355b0 + 235631e commit 47d5887
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion azurerm/resourceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"net/url"
"sort"
"strings"
)

Expand Down Expand Up @@ -115,7 +116,15 @@ func composeAzureResourceID(idObj *ResourceID) (id string, err error) {

id += fmt.Sprintf("/providers/%s", idObj.Provider)

for k, v := range idObj.Path {
// sort the path keys so our output is deterministic
var pathKeys []string
for k := range idObj.Path {
pathKeys = append(pathKeys, k)
}
sort.Strings(pathKeys)

for _, k := range pathKeys {
v := idObj.Path[k]
if k == "" || v == "" {
return "", fmt.Errorf("ResourceID.Path cannot contain empty strings")
}
Expand Down
7 changes: 6 additions & 1 deletion azurerm/resourceid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ func TestComposeAzureResourceID(t *testing.T) {
"k1": "v1",
"k2": "v2",
"k3": "v3",
"k4": "v4",
"k5": "v5",
"k6": "v6",
"k7": "v7",
"k8": "v8",
},
},
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup1/providers/foo.bar/k1/v1/k2/v2/k3/v3",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup1/providers/foo.bar/k1/v1/k2/v2/k3/v3/k4/v4/k5/v5/k6/v6/k7/v7/k8/v8",
false,
},
{
Expand Down

0 comments on commit 47d5887

Please sign in to comment.