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.
This commit is contained in:
James Bardin 2019-03-12 10:03:19 -04:00
parent 4c23e990e2
commit 892674a3f9
1 changed files with 4 additions and 2 deletions

View File

@ -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)
}