From ee52f2664739e9077acbcdaeb3a4cc4c993ea70c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 7 Dec 2020 14:01:44 -0500 Subject: [PATCH] ignore_changes can ignore unknowns too The logic for handling unknown equality was incorrect, and would miss changes where the configuration is still not known during plan. --- terraform/eval_diff.go | 2 +- terraform/eval_diff_test.go | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index bf2c86b31..5124b6cd1 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -673,7 +673,7 @@ func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChanges []hcl // won't cause any changes in the transformation, but allows us to skip // breaking up the maps and checking for key existence here too. eq := p.Equals(c) - if eq.IsKnown() && eq.False() { + if !eq.IsKnown() || eq.False() { // there a change to ignore at this path, store the prior value ignoredValues = append(ignoredValues, ignoreChange{icPath, p, key}) } diff --git a/terraform/eval_diff_test.go b/terraform/eval_diff_test.go index 491b18c72..30d819aad 100644 --- a/terraform/eval_diff_test.go +++ b/terraform/eval_diff_test.go @@ -92,6 +92,30 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) { "b": cty.StringVal("new b value"), }), }, + "map": { + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("a0 value"), + "a1": cty.StringVal("a1 value"), + }), + "b": cty.StringVal("b value"), + }), + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("new a0 value"), + "a1": cty.UnknownVal(cty.String), + }), + "b": cty.StringVal("b value"), + }), + []string{`a`}, + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("a0 value"), + "a1": cty.StringVal("a1 value"), + }), + "b": cty.StringVal("b value"), + }), + }, "map_index": { cty.ObjectVal(map[string]cty.Value{ "a": cty.MapVal(map[string]cty.Value{ @@ -136,6 +160,30 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) { "b": cty.StringVal("b value"), }), }, + "map_index_unknown_value": { + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("a0 value"), + "a1": cty.StringVal("a1 value"), + }), + "b": cty.StringVal("b value"), + }), + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("a0 value"), + "a1": cty.UnknownVal(cty.String), + }), + "b": cty.StringVal("b value"), + }), + []string{`a["a1"]`}, + cty.ObjectVal(map[string]cty.Value{ + "a": cty.MapVal(map[string]cty.Value{ + "a0": cty.StringVal("a0 value"), + "a1": cty.StringVal("a1 value"), + }), + "b": cty.StringVal("b value"), + }), + }, "map_index_multiple_keys": { cty.ObjectVal(map[string]cty.Value{ "a": cty.MapVal(map[string]cty.Value{ @@ -297,6 +345,30 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) { "b": cty.StringVal("new b value"), }), }, + "unknown_object_attribute": { + cty.ObjectVal(map[string]cty.Value{ + "a": cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("a.foo value"), + "bar": cty.StringVal("a.bar value"), + }), + "b": cty.StringVal("b value"), + }), + cty.ObjectVal(map[string]cty.Value{ + "a": cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("new a.foo value"), + "bar": cty.UnknownVal(cty.String), + }), + "b": cty.StringVal("new b value"), + }), + []string{"a.bar"}, + cty.ObjectVal(map[string]cty.Value{ + "a": cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("new a.foo value"), + "bar": cty.StringVal("a.bar value"), + }), + "b": cty.StringVal("new b value"), + }), + }, } for name, test := range tests {