helper/schema: GetOk now only returns true if set to non-zero value

This commit is contained in:
Mitchell Hashimoto 2015-02-17 16:55:39 -08:00
parent b3b8688616
commit 7d32c8946a
2 changed files with 13 additions and 1 deletions

View File

@ -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
}

View File

@ -828,7 +828,7 @@ func TestResourceDataGetOk(t *testing.T) {
Key: "availability_zone",
Value: "",
Ok: true,
Ok: false,
},
{