mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
helper/schema: test real nil pointer to ResourceData.Set
This commit is contained in:
parent
c030148259
commit
58a8776c41
@ -143,11 +143,18 @@ func (d *ResourceData) Set(key string, value interface{}) error {
|
||||
// simplify the interface.
|
||||
reflectVal := reflect.ValueOf(value)
|
||||
if reflectVal.Kind() == reflect.Ptr {
|
||||
if reflectVal.IsNil() {
|
||||
// If the pointer is nil, then the value is just nil
|
||||
value = nil
|
||||
} else {
|
||||
// Otherwise, we dereference the pointer as long as its not
|
||||
// a pointer to a struct, since struct pointers are allowed.
|
||||
reflectVal = reflect.Indirect(reflectVal)
|
||||
if reflectVal.Kind() != reflect.Struct {
|
||||
value = reflectVal.Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return d.setWriter.WriteField(strings.Split(key, "."), value)
|
||||
}
|
||||
|
@ -1178,6 +1178,8 @@ func TestResourceDataHasChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResourceDataSet(t *testing.T) {
|
||||
var testNilPtr *string
|
||||
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.InstanceState
|
||||
@ -1649,7 +1651,7 @@ func TestResourceDataSet(t *testing.T) {
|
||||
Diff: nil,
|
||||
|
||||
Key: "availability_zone",
|
||||
Value: nil,
|
||||
Value: testNilPtr,
|
||||
|
||||
GetKey: "availability_zone",
|
||||
GetValue: "",
|
||||
|
Loading…
Reference in New Issue
Block a user