terraform: ResourceConfig.Equal should sort ComputedKeys

This was causing otherwise equal ResourceConfigs to report non-equal
which was incorrect, thus causing incorrect shadow graph errors.
This commit is contained in:
Mitchell Hashimoto 2016-10-22 12:00:05 -07:00
parent f8e35ecb2f
commit 3dd64d9f2e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
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
}