Merge pull request #9526 from hashicorp/b-resource-config-equal

terraform: ResourceConfig.Equal should sort ComputedKeys
This commit is contained in:
Mitchell Hashimoto 2016-10-22 12:06:20 -07:00 committed by GitHub
commit 7418f6c48f
3 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package terraform
import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
@ -144,6 +145,10 @@ func (c *ResourceConfig) Equal(c2 *ResourceConfig) bool {
return c == c2
}
// Sort the computed keys so they're deterministic
sort.Strings(c.ComputedKeys)
sort.Strings(c2.ComputedKeys)
// Two resource configs if their exported properties are equal.
// We don't compare "raw" because it is never used again after
// initialization and for all intents and purposes they are equal

View File

@ -268,6 +268,20 @@ func TestResourceConfigEqual_nil(t *testing.T) {
}
}
func TestResourceConfigEqual_computedKeyOrder(t *testing.T) {
c := map[string]interface{}{"foo": "${a.b.c}"}
rc := NewResourceConfig(config.TestRawConfig(t, c))
rc2 := NewResourceConfig(config.TestRawConfig(t, c))
// Set the computed keys manual
rc.ComputedKeys = []string{"foo", "bar"}
rc2.ComputedKeys = []string{"bar", "foo"}
if !rc.Equal(rc2) {
t.Fatal("should be equal")
}
}
func testResourceConfig(
t *testing.T, c map[string]interface{}) *ResourceConfig {
raw, err := config.NewRawConfig(c)

View File

@ -140,6 +140,9 @@ func (p *shadowResourceProviderReal) ValidateResource(
Errors: errs,
})
// With it locked, call SetValue again so that it triggers WaitForChange
p.Shared.ValidateResource.SetValue(key, wrapper)
// Return the result
return warns, errs
}