From 76f18cc83c56b0ded6f79bae46f385bc8af1c6b9 Mon Sep 17 00:00:00 2001 From: Venelin Date: Mon, 20 May 2024 00:50:05 +0300 Subject: [PATCH] fix repeated blocks --- pkg/tests/cross-tests/tfwrite.go | 12 ++++++++++-- pkg/tests/cross-tests/tfwrite_test.go | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/tests/cross-tests/tfwrite.go b/pkg/tests/cross-tests/tfwrite.go index 66e98a976..41b52ead2 100644 --- a/pkg/tests/cross-tests/tfwrite.go +++ b/pkg/tests/cross-tests/tfwrite.go @@ -60,8 +60,12 @@ func writeBlock(body *hclwrite.Body, schemas map[string]*schema.Schema, values m continue } - newBlock := body.AppendNewBlock(key, nil) + if value.LengthInt() == 0 { + body.AppendNewBlock(key, nil) + } + for _, v := range value.AsValueSet().Values() { + newBlock := body.AppendNewBlock(key, nil) writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) } } else if sch.Type == schema.TypeList { @@ -69,8 +73,12 @@ func writeBlock(body *hclwrite.Body, schemas map[string]*schema.Schema, values m continue } - newBlock := body.AppendNewBlock(key, nil) + if value.LengthInt() == 0 { + body.AppendNewBlock(key, nil) + } + for _, v := range value.AsValueSlice() { + newBlock := body.AppendNewBlock(key, nil) writeBlock(newBlock.Body(), elem.Schema, v.AsValueMap()) } } else { diff --git a/pkg/tests/cross-tests/tfwrite_test.go b/pkg/tests/cross-tests/tfwrite_test.go index e433c4922..03c84b1ac 100644 --- a/pkg/tests/cross-tests/tfwrite_test.go +++ b/pkg/tests/cross-tests/tfwrite_test.go @@ -168,6 +168,7 @@ resource "res" "ex" { } `), }, + // TODO: empty list/set test case } for _, tc := range testCases {