Merge pull request #27174 from hashicorp/jbardin/ignore-unknown

ignore_changes can ignore unknowns too
This commit is contained in:
James Bardin 2020-12-07 17:40:21 -05:00 committed by GitHub
commit 627a2121b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 1 deletions

View File

@ -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 // won't cause any changes in the transformation, but allows us to skip
// breaking up the maps and checking for key existence here too. // breaking up the maps and checking for key existence here too.
eq := p.Equals(c) 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 // there a change to ignore at this path, store the prior value
ignoredValues = append(ignoredValues, ignoreChange{icPath, p, key}) ignoredValues = append(ignoredValues, ignoreChange{icPath, p, key})
} }

View File

@ -92,6 +92,30 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) {
"b": cty.StringVal("new b value"), "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": { "map_index": {
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
"a": cty.MapVal(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"), "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": { "map_index_multiple_keys": {
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
"a": cty.MapVal(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"), "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 { for name, test := range tests {