From 5f3068be2cef706bc040174ecf73e4887cf4209c Mon Sep 17 00:00:00 2001 From: Jordi Fernandez Date: Thu, 12 Sep 2024 14:41:53 +0200 Subject: [PATCH] Fix panic when field is an empty list (#1399) --- kong2tf/generate_resource.go | 3 +++ kong2tf/generate_resource_test.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kong2tf/generate_resource.go b/kong2tf/generate_resource.go index 07295ee57..1e293cfca 100644 --- a/kong2tf/generate_resource.go +++ b/kong2tf/generate_resource.go @@ -353,6 +353,9 @@ func outputList(entityType string, key string, input []interface{}, depth int) s // Ends a list rendering in Go func endList(input []interface{}, depth int) string { + if len(input) == 0 { + return "]\n" + } lastLine := line("]", depth, "\n") if _, ok := input[len(input)-1].(map[string]interface{}); ok { return lastLine diff --git a/kong2tf/generate_resource_test.go b/kong2tf/generate_resource_test.go index c5cf122d3..146c83aaa 100644 --- a/kong2tf/generate_resource_test.go +++ b/kong2tf/generate_resource_test.go @@ -22,7 +22,8 @@ func TestGenerateComplexLayout(t *testing.T) { "nested_nested_nested_field1": "nested_nested_nested_string" } } - } + }, + "field4": [] }` var entity map[string]any @@ -43,6 +44,7 @@ func TestGenerateComplexLayout(t *testing.T) { } } } + field4 = [] service = { id = konnect_gateway_service.some_service.id