Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions terraform/eval_read_data_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions terraform/eval_read_data_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down