From 5eb0750f7299b4f9ad663c078aef1b8e25f1ed2b Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 12 Jul 2019 16:33:18 -0400 Subject: [PATCH] don't assert set block length with unknowns If a planned NestingList block value looks like it may represent a dynamic block, we don't check the length since it may be unknown. This check was missing in the NestingSet case, but it applies for the same reason. < --- plans/objchange/compatible.go | 8 +++++++ plans/objchange/compatible_test.go | 34 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/plans/objchange/compatible.go b/plans/objchange/compatible.go index 8a74c07feddb..cd001c733dd1 100644 --- a/plans/objchange/compatible.go +++ b/plans/objchange/compatible.go @@ -169,6 +169,14 @@ func assertObjectCompatible(schema *configschema.Block, planned, actual cty.Valu }) errs = append(errs, setErrs...) + if maybeUnknownBlocks { + // When unknown blocks are present the final blocks may be + // at different indices than the planned blocks, so unfortunately + // we can't do our usual checks in this case without generating + // false negatives. + continue + } + // There can be fewer elements in a set after its elements are all // known (values that turn out to be equal will coalesce) but the // number of elements must never get larger. diff --git a/plans/objchange/compatible_test.go b/plans/objchange/compatible_test.go index 2841ec26b932..473ee51195ae 100644 --- a/plans/objchange/compatible_test.go +++ b/plans/objchange/compatible_test.go @@ -1068,9 +1068,9 @@ func TestAssertObjectCompatible(t *testing.T) { }), }), }), - []string{ - `.block: block set length changed from 2 to 3`, - }, + // there is no error here, because the presence of unknowns + // indicates this may be a dynamic block, and the length is unknown + nil, }, { &configschema.Block{ @@ -1135,6 +1135,34 @@ func TestAssertObjectCompatible(t *testing.T) { }), nil, }, + { + &configschema.Block{ + BlockTypes: map[string]*configschema.NestedBlock{ + "block": { + Nesting: configschema.NestingSet, + Block: schemaWithFoo, + }, + }, + }, + cty.ObjectVal(map[string]cty.Value{ + "block": cty.SetVal([]cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + "foo": cty.UnknownVal(cty.String), + }), + }), + }), + cty.ObjectVal(map[string]cty.Value{ + "block": cty.SetVal([]cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("a"), + }), + cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal("b"), + }), + }), + }), + nil, + }, { &configschema.Block{ BlockTypes: map[string]*configschema.NestedBlock{