core: MockProvider legacy ApplyFn handling correct behavior of nil

In the old protocol, returning a nil InstanceState was a way to indicate
that the object had been deleted. In the new world we signal that with
an actual object that contains a null value, which Terraform Core itself
will then recognize and turn into a nil state, eventually removing the
entry from state altogether.
This commit is contained in:
Martin Atkins 2018-09-11 16:38:14 -07:00
parent a595194657
commit 26aef7dc22
1 changed files with 12 additions and 3 deletions

View File

@ -379,9 +379,18 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err)
}
newVal, err := newState.AttrsAsObjectValue(schema.Block.ImpliedType())
if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err)
var newVal cty.Value
if newState != nil {
var err error
newVal, err = newState.AttrsAsObjectValue(schema.Block.ImpliedType())
if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err)
}
} else {
// If apply returned a nil new state then that's the old way to
// indicate that the object was destroyed. Our new interface calls
// for that to be signalled as a null value.
newVal = cty.NullVal(schema.Block.ImpliedType())
}
resp.NewState = newVal