From 892674a3f93c5189e6408501926fe0d284b43dd1 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 12 Mar 2019 10:03:19 -0400 Subject: [PATCH] don't recalculate existing block counts in diff If a block is uneffected by diffs, keep the block count value regardless of what it is. Blocks containing zero values will often be represented by only the count value. --- terraform/diff.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/terraform/diff.go b/terraform/diff.go index 3f26117a8..a5d70e264 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -460,7 +460,6 @@ func (d *InstanceDiff) Apply(attrs map[string]string, schema *configschema.Block func (d *InstanceDiff) applyBlockDiff(path []string, attrs map[string]string, schema *configschema.Block) (map[string]string, error) { result := map[string]string{} - name := "" if len(path) > 0 { name = path[len(path)-1] @@ -597,7 +596,8 @@ func (d *InstanceDiff) applyBlockDiff(path []string, attrs map[string]string, sc } } - if countDiff, ok := d.Attributes[strings.Join(append(path, n, "#"), ".")]; ok { + countAddr := strings.Join(append(path, n, "#"), ".") + if countDiff, ok := d.Attributes[countAddr]; ok { if countDiff.NewComputed { result[localBlockPrefix+"#"] = hcl2shim.UnknownVariableValue } else { @@ -633,6 +633,8 @@ func (d *InstanceDiff) applyBlockDiff(path []string, attrs map[string]string, sc } } } + } else if origCount, ok := attrs[countAddr]; ok && keepBlock { + result[localBlockPrefix+"#"] = origCount } else { result[localBlockPrefix+"#"] = countFlatmapContainerValues(localBlockPrefix+"#", result) }