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:
parent
a595194657
commit
26aef7dc22
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue