Skip to content

Commit d0eda6b

Browse files
committed
add comment and rename helper function
1 parent 40cac56 commit d0eda6b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

internal/provider/datasources/data_source_deployments.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ func (d *deploymentsDataSource) Read(
8383
params := &platform.ListDeploymentsParams{
8484
Limit: lo.ToPtr(1000),
8585
}
86-
params.DeploymentIds = utils.TypesListToStringSlice(data.DeploymentIds)
87-
params.WorkspaceIds = utils.TypesListToStringSlice(data.WorkspaceIds)
88-
params.Names = utils.TypesListToStringSlice(data.Names)
86+
params.DeploymentIds = utils.TypesListToStringSlicePtr(data.DeploymentIds)
87+
params.WorkspaceIds = utils.TypesListToStringSlicePtr(data.WorkspaceIds)
88+
params.Names = utils.TypesListToStringSlicePtr(data.Names)
8989

9090
if resp.Diagnostics.HasError() {
9191
return

internal/provider/datasources/data_source_workspaces.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func (d *workspacesDataSource) Read(
8383
params := &platform.ListWorkspacesParams{
8484
Limit: lo.ToPtr(1000),
8585
}
86-
params.WorkspaceIds = utils.TypesListToStringSlice(data.WorkspaceIds)
87-
params.Names = utils.TypesListToStringSlice(data.Names)
86+
params.WorkspaceIds = utils.TypesListToStringSlicePtr(data.WorkspaceIds)
87+
params.Names = utils.TypesListToStringSlicePtr(data.Names)
8888

8989
if resp.Diagnostics.HasError() {
9090
return

internal/utils/list.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ func ObjectList[T any](ctx context.Context, values []T, objectAttributeTypes map
4141
return objectList, nil
4242
}
4343

44-
// TypesListToStringSlice converts a types.List to a pointer to a slice of strings
44+
// TypesListToStringSlicePtr converts a types.List to a pointer to a slice of strings
4545
// This is useful for converting a list of strings from the Terraform framework to a slice of strings used for calling the API
46-
func TypesListToStringSlice(list types.List) *[]string {
46+
// We prefer to use a pointer to a slice of strings because our API client query params usually have type *[]string
47+
// and we can easily assign the query param to the result of this function (regardless if the result is nil or not)
48+
func TypesListToStringSlicePtr(list types.List) *[]string {
4749
elements := list.Elements()
4850
if len(elements) == 0 {
4951
return nil

0 commit comments

Comments
 (0)