From 40174b634ac54e3f4926ede57e642a346740d780 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 11 Nov 2021 10:15:29 -0500 Subject: [PATCH] ignore_changes changing a null map to empty Fix an error where using `ignore_changes` would cause some null maps to be saved as an empty map. --- internal/terraform/node_resource_abstract_instance.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/terraform/node_resource_abstract_instance.go b/internal/terraform/node_resource_abstract_instance.go index 3cab2b181..b7b781191 100644 --- a/internal/terraform/node_resource_abstract_instance.go +++ b/internal/terraform/node_resource_abstract_instance.go @@ -1289,10 +1289,15 @@ func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChangesPath [ } var newVal cty.Value - if len(configMap) == 0 { - newVal = cty.MapValEmpty(v.Type().ElementType()) - } else { + switch { + case len(configMap) > 0: newVal = cty.MapVal(configMap) + case v.IsNull(): + // if the config value was null, and no values remain in the map, + // reset the value to null. + newVal = v + default: + newVal = cty.MapValEmpty(v.Type().ElementType()) } if len(vMarks) > 0 {