Skip to content

Commit

Permalink
fix: empty datasource results should be empty arrays (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 authored Sep 10, 2024
1 parent 5aa239f commit 359e287
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion octopusdeploy_framework/datasource_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq
return
}

var mappedEnvironments []schemas.EnvironmentTypeResourceModel
mappedEnvironments := []schemas.EnvironmentTypeResourceModel{}
if data.Name.IsNull() {
tflog.Debug(ctx, fmt.Sprintf("environments returned from API: %#v", existingEnvironments))
for _, environment := range existingEnvironments.Items {
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy_framework/datasource_project_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *projectGroupsDataSource) Read(ctx context.Context, req datasource.ReadR
return
}

var newGroups []schemas.ProjectGroupTypeResourceModel
newGroups := []schemas.ProjectGroupTypeResourceModel{}
for _, projectGroup := range existingProjectGroups.Items {
tflog.Debug(ctx, "loaded group "+projectGroup.Name)
var g schemas.ProjectGroupTypeResourceModel
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy_framework/datasource_spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

var mappedSpaces []schemas.SpaceModel
mappedSpaces := []schemas.SpaceModel{}
for _, space := range existingSpaces.Items {
var s schemas.SpaceModel
mapSpaceToState(ctx, &s, space)
Expand Down
7 changes: 4 additions & 3 deletions octopusdeploy_framework/datasource_tag_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest

util.DatasourceResultCount(ctx, "tag sets", len(existingTagSets.Items))

data.TagSets = flattenTagSets(existingTagSets.Items)
data.TagSets = flattenTagSets(ctx, existingTagSets.Items)
data.ID = types.StringValue(fmt.Sprintf("TagSets-%s", time.Now().UTC().String()))

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func flattenTagSets(tagSets []*tagsets.TagSet) types.List {
func flattenTagSets(ctx context.Context, tagSets []*tagsets.TagSet) types.List {
if len(tagSets) == 0 {
return types.ListNull(types.ObjectType{AttrTypes: schemas.GetTagSetAttrTypes()})
emptyList, _ := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: schemas.GetTagSetAttrTypes()}, tagSets)
return emptyList
}

tfList := make([]attr.Value, len(tagSets))
Expand Down

0 comments on commit 359e287

Please sign in to comment.