diff --git a/pkg/generators/terraform_generator.go b/pkg/generators/terraform_generator.go index 0793f4978..aab2b66a0 100644 --- a/pkg/generators/terraform_generator.go +++ b/pkg/generators/terraform_generator.go @@ -354,6 +354,15 @@ func formatValue(value any) string { switch v := value.(type) { case string: return fmt.Sprintf("%q", v) + case []string: + if len(v) == 0 { + return "[]" + } + var items []string + for _, item := range v { + items = append(items, fmt.Sprintf("%q", item)) + } + return fmt.Sprintf("[%s]", strings.Join(items, ", ")) case []any: if len(v) == 0 { return "[]" @@ -407,6 +416,15 @@ func convertToCtyValue(value any) cty.Value { return cty.NumberFloatVal(v) case bool: return cty.BoolVal(v) + case []string: + if len(v) == 0 { + return cty.ListValEmpty(cty.String) + } + var ctyList []cty.Value + for _, item := range v { + ctyList = append(ctyList, cty.StringVal(item)) + } + return cty.ListVal(ctyList) case []any: if len(v) == 0 { return cty.ListValEmpty(cty.DynamicPseudoType) diff --git a/pkg/generators/terraform_generator_test.go b/pkg/generators/terraform_generator_test.go index f985efcfd..ca05751d4 100644 --- a/pkg/generators/terraform_generator_test.go +++ b/pkg/generators/terraform_generator_test.go @@ -477,6 +477,16 @@ func TestConvertToCtyValue(t *testing.T) { input: map[string]any{"key": "value"}, expected: cty.ObjectVal(map[string]cty.Value{"key": cty.StringVal("value")}), }, + { + name: "StringSliceEmpty", + input: []string{}, + expected: cty.ListValEmpty(cty.String), + }, + { + name: "StringSliceNonEmpty", + input: []string{"a", "b"}, + expected: cty.ListVal([]cty.Value{cty.StringVal("a"), cty.StringVal("b")}), + }, { name: "Unsupported", input: struct{}{}, @@ -607,6 +617,13 @@ func TestFormatValue(t *testing.T) { } }) + t.Run("StringSliceEmpty", func(t *testing.T) { + result := formatValue([]string{}) + if result != "[]" { + t.Errorf("expected [] got %q", result) + } + }) + t.Run("NilValue", func(t *testing.T) { result := formatValue(nil) if result != "null" { @@ -641,6 +658,13 @@ func TestFormatValue(t *testing.T) { } }) + t.Run("StringSliceNonEmpty", func(t *testing.T) { + result := formatValue([]string{"a", "b"}) + if result != "[\"a\", \"b\"]" { + t.Errorf("expected [\"a\", \"b\"] got %q", result) + } + }) + t.Run("EmptyAddons", func(t *testing.T) { input := map[string]any{ "addons": map[string]any{