Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't panic with a null list block value in config #32428

Merged
merged 1 commit into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/plans/objchange/plan_valid.go
Expand Up @@ -101,6 +101,14 @@ func assertPlanValid(schema *configschema.Block, priorState, config, plannedStat
continue
}

if configV.IsNull() {
// Configuration cannot decode a block into a null value, but
// we could be dealing with a null returned by a legacy
// provider and inserted via ignore_changes. Fix the value in
// place so the length can still be compared.
configV = cty.ListValEmpty(configV.Type().ElementType())
}

plannedL := plannedV.LengthInt()
configL := configV.LengthInt()
if plannedL != configL {
Expand Down
37 changes: 36 additions & 1 deletion internal/plans/objchange/plan_valid_test.go
Expand Up @@ -389,6 +389,41 @@ func TestAssertPlanValid(t *testing.T) {
},
},

// but don't panic on a null list just in case
"nested list, null in config": {
&configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
"b": {
Nesting: configschema.NestingList,
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"c": {
Type: cty.String,
Optional: true,
},
},
},
},
},
},
cty.ObjectVal(map[string]cty.Value{
"b": cty.ListValEmpty(cty.Object(map[string]cty.Type{
"c": cty.String,
})),
}),
cty.ObjectVal(map[string]cty.Value{
"b": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{
"c": cty.String,
}))),
}),
cty.ObjectVal(map[string]cty.Value{
"b": cty.ListValEmpty(cty.Object(map[string]cty.Type{
"c": cty.String,
})),
}),
nil,
},

// blocks can be unknown when using dynamic
"nested list, unknown nested dynamic": {
&configschema.Block{
Expand Down Expand Up @@ -1671,7 +1706,7 @@ func TestAssertPlanValid(t *testing.T) {

t.Logf(
"\nprior: %sconfig: %splanned: %s",
dump.Value(test.Planned),
dump.Value(test.Prior),
dump.Value(test.Config),
dump.Value(test.Planned),
)
Expand Down