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
18 changes: 18 additions & 0 deletions pkg/generators/terraform_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[]"
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions pkg/generators/terraform_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{},
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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{
Expand Down
Loading