helper/plugin: ReadResource to deal with missing remote object

This commit is contained in:
Martin Atkins 2018-08-27 17:43:37 -07:00
parent 1d672623eb
commit 97da905c6e
1 changed files with 14 additions and 0 deletions

View File

@ -331,6 +331,20 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso
return resp, nil
}
if newInstanceState == nil || newInstanceState.ID == "" {
// The old provider API used an empty id to signal that the remote
// object appears to have been deleted, but our new protocol expects
// to see a null value (in the cty sense) in that case.
newConfigMP, err := msgpack.Marshal(cty.NullVal(block.ImpliedType()), block.ImpliedType())
if err != nil {
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
}
resp.NewState = &proto.DynamicValue{
Msgpack: newConfigMP,
}
return resp, nil
}
// helper/schema should always copy the ID over, but do it again just to be safe
newInstanceState.Attributes["id"] = newInstanceState.ID