Merge pull request #26028 from hashicorp/alisdair/fix-eval-read-data-panic
terraform: Fix createEmptyBlocks NestingSingle bug
This commit is contained in:
commit
8198e9758c
|
@ -239,8 +239,6 @@ func createEmptyBlocks(schema *configschema.Block, val cty.Value) cty.Value {
|
|||
continue
|
||||
}
|
||||
|
||||
ety := block.Type().ElementType()
|
||||
|
||||
// helper to build the recursive block values
|
||||
nextBlocks := func() []cty.Value {
|
||||
// this is only called once we know this is a non-null List or Set
|
||||
|
@ -259,6 +257,7 @@ func createEmptyBlocks(schema *configschema.Block, val cty.Value) cty.Value {
|
|||
// We are only concerned with block types that can come from the legacy
|
||||
// sdk, which means TypeList or TypeSet.
|
||||
case configschema.NestingList:
|
||||
ety := block.Type().ElementType()
|
||||
switch {
|
||||
case block.IsNull():
|
||||
objMap[name] = cty.ListValEmpty(ety)
|
||||
|
@ -269,6 +268,7 @@ func createEmptyBlocks(schema *configschema.Block, val cty.Value) cty.Value {
|
|||
}
|
||||
|
||||
case configschema.NestingSet:
|
||||
ety := block.Type().ElementType()
|
||||
switch {
|
||||
case block.IsNull():
|
||||
objMap[name] = cty.SetValEmpty(ety)
|
||||
|
|
|
@ -86,6 +86,22 @@ func TestReadDataCreateEmptyBlocks(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
singleSchema := &configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"single": {
|
||||
Nesting: configschema.NestingSingle,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"attr": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
schema *configschema.Block
|
||||
|
@ -330,6 +346,20 @@ func TestReadDataCreateEmptyBlocks(t *testing.T) {
|
|||
}),
|
||||
}),
|
||||
},
|
||||
{
|
||||
"single-block-null",
|
||||
singleSchema,
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"single": cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"attr": cty.String,
|
||||
})),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"single": cty.NullVal(cty.Object(map[string]cty.Type{
|
||||
"attr": cty.String,
|
||||
})),
|
||||
}),
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
val := createEmptyBlocks(tc.schema, tc.val)
|
||||
|
|
Loading…
Reference in New Issue