File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,12 +16,17 @@ func childAttributeIsOptional(att *tfjson.SchemaAttribute) bool {
1616 return att .Optional
1717}
1818
19- // childBlockIsOptional returns true for blocks with with min items 0 and any required or optional children.
19+ // childBlockIsOptional returns true for blocks with with min items 0
20+ // which are either empty or have any required or optional children.
2021func childBlockIsOptional (block * tfjson.SchemaBlockType ) bool {
2122 if block .MinItems > 0 {
2223 return false
2324 }
2425
26+ if len (block .Block .NestedBlocks ) == 0 && len (block .Block .Attributes ) == 0 {
27+ return true
28+ }
29+
2530 for _ , childBlock := range block .Block .NestedBlocks {
2631 if childBlockIsRequired (childBlock ) {
2732 return true
Original file line number Diff line number Diff line change @@ -324,6 +324,16 @@ func TestChildBlockIsOptional(t *testing.T) {
324324 },
325325 false ,
326326 },
327+ {
328+ "empty block" ,
329+ & tfjson.SchemaBlockType {
330+ NestingMode : tfjson .SchemaNestingModeSingle ,
331+ Block : & tfjson.SchemaBlock {
332+ Description : "This is an empty block." ,
333+ },
334+ },
335+ true ,
336+ },
327337 } {
328338 t .Run (c .name , func (t * testing.T ) {
329339 actual := childBlockIsOptional (c .block )
You can’t perform that action at this time.
0 commit comments