1->0 set changes non longer should happen in Read

The new normalization should make preventing those changes unnecessary,
and will also prevent extra empty elements from being added when
resources are refreshed.
This commit is contained in:
James Bardin 2019-02-28 17:47:11 -05:00
parent 0dc3ca966a
commit 9a39af5047
2 changed files with 6 additions and 1 deletions

View File

@ -431,7 +431,7 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso
// 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)
newInstanceState.Attributes = normalizeFlatmapContainers(stateAttrs, newInstanceState.Attributes, false)
}
if newInstanceState == nil || newInstanceState.ID == "" {

View File

@ -709,6 +709,11 @@ func TestNormalizeFlatmapContainers(t *testing.T) {
attrs: map[string]string{"map.%": "0", "list.#": "0", "id": "1"},
expect: map[string]string{"id": "1", "map.%": "0", "list.#": "0"},
},
{
prior: map[string]string{"list.#": "1", "list.0": "old value"},
attrs: map[string]string{"list.#": "0"},
expect: map[string]string{},
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
got := normalizeFlatmapContainers(tc.prior, tc.attrs, false)