helper/schema: GetOk now only returns true if set to non-zero value
This commit is contained in:
parent
b3b8688616
commit
7d32c8946a
|
@ -77,6 +77,18 @@ func (d *ResourceData) GetChange(key string) (interface{}, interface{}) {
|
|||
func (d *ResourceData) GetOk(key string) (interface{}, bool) {
|
||||
r := d.getRaw(key, getSourceSet)
|
||||
exists := r.Exists && !r.Computed
|
||||
if exists {
|
||||
// If it exists, we also want to verify it is not the zero-value.
|
||||
value := r.Value
|
||||
zero := r.Schema.Type.Zero()
|
||||
|
||||
if eq, ok := value.(Equal); ok {
|
||||
exists = !eq.Equal(zero)
|
||||
} else {
|
||||
exists = !reflect.DeepEqual(value, zero)
|
||||
}
|
||||
}
|
||||
|
||||
return r.Value, exists
|
||||
}
|
||||
|
||||
|
|
|
@ -828,7 +828,7 @@ func TestResourceDataGetOk(t *testing.T) {
|
|||
|
||||
Key: "availability_zone",
|
||||
Value: "",
|
||||
Ok: true,
|
||||
Ok: false,
|
||||
},
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue