Skip to content

Commit

Permalink
don't assert set block length with unknowns
Browse files Browse the repository at this point in the history
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.

<
  • Loading branch information
jbardin committed Jul 12, 2019
1 parent a20e209 commit 5eb0750
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
8 changes: 8 additions & 0 deletions plans/objchange/compatible.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 31 additions & 3 deletions plans/objchange/compatible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 5eb0750

Please sign in to comment.