From e8096e9c8bb01a32efe13383f501579abc852c5a Mon Sep 17 00:00:00 2001 From: James Bardin Date: Sat, 12 Jan 2019 10:38:38 -0500 Subject: [PATCH] normalize values during ReadResource Match the normalization behavior of Apply, so we don't end up causing any diffs between zero values when refreshing resources. --- helper/plugin/grpc_provider.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helper/plugin/grpc_provider.go b/helper/plugin/grpc_provider.go index c9ffa1a23..d3ff07717 100644 --- a/helper/plugin/grpc_provider.go +++ b/helper/plugin/grpc_provider.go @@ -421,6 +421,13 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso return resp, nil } + if newInstanceState != nil { + // here we use the prior state to check for unknown/zero containers values + // when normalizing the flatmap. + stateAttrs := hcl2shim.FlatmapValueFromHCL2(stateVal) + newInstanceState.Attributes = normalizeFlatmapContainers(stateAttrs, newInstanceState.Attributes, true) + } + 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 @@ -445,6 +452,7 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso } newStateVal = copyTimeoutValues(newStateVal, stateVal) + newStateVal = copyMissingValues(newStateVal, stateVal) newStateMP, err := msgpack.Marshal(newStateVal, block.ImpliedType()) if err != nil { @@ -521,7 +529,7 @@ func (s *GRPCProviderServer) PlanResourceChange(_ context.Context, req *proto.Pl // strip out non-diffs for k, v := range diff.Attributes { - if v.New == v.Old && !v.NewComputed && !v.NewRemoved { + if v.New == v.Old && !v.NewComputed { delete(diff.Attributes, k) } } @@ -705,7 +713,7 @@ func (s *GRPCProviderServer) ApplyResourceChange(_ context.Context, req *proto.A // strip out non-diffs for k, v := range diff.Attributes { - if v.New == v.Old && !v.NewComputed && !v.NewRemoved && v.NewExtra == "" { + if v.New == v.Old && !v.NewComputed && v.NewExtra == "" { delete(diff.Attributes, k) } }