Skip to content

Commit 3a1c33d

Browse files
committed
fix(conversion) implement StringSetToPointer with StringSetToSlice
1 parent 62ab6fe commit 3a1c33d

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

stackit/internal/conversion/conversion.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,8 @@ func StringListToPointer(list basetypes.ListValue) (*[]string, error) {
151151
// It returns nil if the value is null or unknown.
152152
// Note: It sorts the resulting slice to ensure deterministic behavior.
153153
func StringSetToPointer(set basetypes.SetValue) (*[]string, error) {
154-
if set.IsNull() || set.IsUnknown() {
155-
return nil, nil
156-
}
157-
158-
elements := set.Elements()
159-
result := make([]string, 0, len(elements))
160-
161-
for i, el := range elements {
162-
elStr, ok := el.(types.String)
163-
if !ok {
164-
return nil, fmt.Errorf("element %d in set is not a string (type: %T)", i, el)
165-
}
166-
result = append(result, elStr.ValueString())
167-
}
168-
169-
// Because Sets are unordered in Terraform, we sort here to
170-
// prevent non-deterministic behavior in the provider logic or API calls.
171-
sort.Strings(result)
172-
173-
return &result, nil
154+
result, err := StringSetToSlice(set)
155+
return &result, err
174156
}
175157

176158
// StringSetToSlice converts basetypes.SetValue to a slice of strings.

0 commit comments

Comments
 (0)