terraform: better detection of unknown values in ResourceConfig, tests
This commit is contained in:
parent
2d656b484c
commit
0c271b2b2d
|
@ -273,6 +273,7 @@ func (c *ResourceConfig) get(
|
|||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
current = v.Interface()
|
||||
case reflect.Slice:
|
||||
previous = current
|
||||
|
@ -298,12 +299,6 @@ func (c *ResourceConfig) get(
|
|||
current = cv.Index(int(i)).Interface()
|
||||
}
|
||||
case reflect.String:
|
||||
// If the value is just the unknown value, then we don't
|
||||
// know anything beyond here.
|
||||
if current == unknownValue() {
|
||||
return current, false
|
||||
}
|
||||
|
||||
// This happens when map keys contain "." and have a common
|
||||
// prefix so were split as path components above.
|
||||
actualKey := strings.Join(parts[i-1:], ".")
|
||||
|
@ -316,6 +311,12 @@ func (c *ResourceConfig) get(
|
|||
}
|
||||
}
|
||||
|
||||
// If the value is just the unknown value, then we don't
|
||||
// know anything beyond here.
|
||||
if current == unknownValue() {
|
||||
return current, false
|
||||
}
|
||||
|
||||
return current, true
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func TestInstanceInfo(t *testing.T) {
|
|||
func TestResourceConfigGet(t *testing.T) {
|
||||
cases := []struct {
|
||||
Config map[string]interface{}
|
||||
Vars map[string]string
|
||||
Vars map[string]interface{}
|
||||
Key string
|
||||
Value interface{}
|
||||
}{
|
||||
|
@ -70,9 +70,9 @@ func TestResourceConfigGet(t *testing.T) {
|
|||
Config: map[string]interface{}{
|
||||
"foo": "${var.foo}",
|
||||
},
|
||||
Vars: map[string]string{"foo": "bar"},
|
||||
Vars: map[string]interface{}{"foo": unknownValue()},
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Value: "${var.foo}",
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -199,7 +199,12 @@ func TestResourceConfigGet(t *testing.T) {
|
|||
if tc.Vars != nil {
|
||||
vs := make(map[string]ast.Variable)
|
||||
for k, v := range tc.Vars {
|
||||
vs["var."+k] = ast.Variable{Value: v, Type: ast.TypeString}
|
||||
hilVar, err := hil.InterfaceToVariable(v)
|
||||
if err != nil {
|
||||
t.Fatalf("%#v to var: %s", v, err)
|
||||
}
|
||||
|
||||
vs["var."+k] = hilVar
|
||||
}
|
||||
|
||||
if err := rawC.Interpolate(vs); err != nil {
|
||||
|
@ -212,6 +217,8 @@ func TestResourceConfigGet(t *testing.T) {
|
|||
|
||||
// Test getting a key
|
||||
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
||||
t.Logf("Config: %#v", rc)
|
||||
|
||||
v, _ := rc.Get(tc.Key)
|
||||
if !reflect.DeepEqual(v, tc.Value) {
|
||||
t.Fatalf("%d bad: %#v", i, v)
|
||||
|
|
Loading…
Reference in New Issue