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
5 changes: 4 additions & 1 deletion plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func toCtyValue(a any) (cty.Value, error) {
}
sv = append(sv, v)
}
return cty.ListVal(sv), nil

// Always use a tuple over a list. Tuples are heterogeneous typed lists, which is
// more robust. Functionally equivalent for our use case of looking up values.
return cty.TupleVal(sv), nil
case reflect.Map:
if av.Type().Key().Kind() != reflect.String {
return cty.NilVal, fmt.Errorf("map keys must be string, found %q", av.Type().Key().Kind())
Expand Down
32 changes: 32 additions & 0 deletions plan_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package preview

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/zclconf/go-cty/cty"
)

func Test_toCtyValue(t *testing.T) {
t.Parallel()

t.Run("EmptyList", func(t *testing.T) {
t.Parallel()
val, err := toCtyValue([]any{})
require.NoError(t, err)
require.True(t, val.Type().IsTupleType())
})

t.Run("HeterogeneousList", func(t *testing.T) {
t.Parallel()
val, err := toCtyValue([]any{5, "hello", true})
require.NoError(t, err)
require.True(t, val.Type().IsTupleType())
require.Equal(t, 3, val.LengthInt())
require.True(t, val.Equals(cty.TupleVal([]cty.Value{
cty.NumberIntVal(5),
cty.StringVal("hello"),
cty.BoolVal(true),
})).True())
})
}
Loading