mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
current = v.Interface()
|
current = v.Interface()
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
previous = current
|
previous = current
|
||||||
@ -298,12 +299,6 @@ func (c *ResourceConfig) get(
|
|||||||
current = cv.Index(int(i)).Interface()
|
current = cv.Index(int(i)).Interface()
|
||||||
}
|
}
|
||||||
case reflect.String:
|
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
|
// This happens when map keys contain "." and have a common
|
||||||
// prefix so were split as path components above.
|
// prefix so were split as path components above.
|
||||||
actualKey := strings.Join(parts[i-1:], ".")
|
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
|
return current, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func TestInstanceInfo(t *testing.T) {
|
|||||||
func TestResourceConfigGet(t *testing.T) {
|
func TestResourceConfigGet(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Config map[string]interface{}
|
Config map[string]interface{}
|
||||||
Vars map[string]string
|
Vars map[string]interface{}
|
||||||
Key string
|
Key string
|
||||||
Value interface{}
|
Value interface{}
|
||||||
}{
|
}{
|
||||||
@ -70,9 +70,9 @@ func TestResourceConfigGet(t *testing.T) {
|
|||||||
Config: map[string]interface{}{
|
Config: map[string]interface{}{
|
||||||
"foo": "${var.foo}",
|
"foo": "${var.foo}",
|
||||||
},
|
},
|
||||||
Vars: map[string]string{"foo": "bar"},
|
Vars: map[string]interface{}{"foo": unknownValue()},
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Value: "bar",
|
Value: "${var.foo}",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -199,7 +199,12 @@ func TestResourceConfigGet(t *testing.T) {
|
|||||||
if tc.Vars != nil {
|
if tc.Vars != nil {
|
||||||
vs := make(map[string]ast.Variable)
|
vs := make(map[string]ast.Variable)
|
||||||
for k, v := range tc.Vars {
|
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 {
|
if err := rawC.Interpolate(vs); err != nil {
|
||||||
@ -212,6 +217,8 @@ func TestResourceConfigGet(t *testing.T) {
|
|||||||
|
|
||||||
// Test getting a key
|
// Test getting a key
|
||||||
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
||||||
|
t.Logf("Config: %#v", rc)
|
||||||
|
|
||||||
v, _ := rc.Get(tc.Key)
|
v, _ := rc.Get(tc.Key)
|
||||||
if !reflect.DeepEqual(v, tc.Value) {
|
if !reflect.DeepEqual(v, tc.Value) {
|
||||||
t.Fatalf("%d bad: %#v", i, v)
|
t.Fatalf("%d bad: %#v", i, v)
|
||||||
|
Loading…
Reference in New Issue
Block a user