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:
parent
f8e35ecb2f
commit
3dd64d9f2e
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue