From 6ecf9b143bf3f87b611b0a966bd399616e639bbb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 12 Mar 2019 16:00:25 -0400 Subject: [PATCH] we can normalize nulls in Read again This should be the final change from removing the flatmap normalization. Since we're no longer trying to a consistent zero or null value in the flatmap config, rather we're trying to maintain the previously applied value, ReadResource also needs to apply the normalizeNullValues step in order to prevent unexpected diffs. --- builtin/providers/test/resource.go | 9 +++++++++ helper/plugin/grpc_provider.go | 1 + 2 files changed, 10 insertions(+) diff --git a/builtin/providers/test/resource.go b/builtin/providers/test/resource.go index 79c5b4a45e..c8556a2b71 100644 --- a/builtin/providers/test/resource.go +++ b/builtin/providers/test/resource.go @@ -163,6 +163,15 @@ func testResourceRead(d *schema.ResourceData, meta interface{}) error { d.Set("computed_map", map[string]string{"key1": "value1"}) d.Set("computed_list", []string{"listval1", "listval2"}) d.Set("computed_set", []string{"setval1", "setval2"}) + + // if there is no "set" value, erroneously set it to an empty set. This + // might change a null value to an empty set, but we should be able to + // ignore that. + s := d.Get("set") + if s == nil || s.(*schema.Set).Len() == 0 { + d.Set("set", []interface{}{}) + } + return nil } diff --git a/helper/plugin/grpc_provider.go b/helper/plugin/grpc_provider.go index fc2bfea2f7..6cdaaa1d98 100644 --- a/helper/plugin/grpc_provider.go +++ b/helper/plugin/grpc_provider.go @@ -448,6 +448,7 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso return resp, nil } + newStateVal = normalizeNullValues(newStateVal, stateVal, false) newStateVal = copyTimeoutValues(newStateVal, stateVal) newStateMP, err := msgpack.Marshal(newStateVal, block.ImpliedType())