Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 359e287

Browse files
authored
fix: empty datasource results should be empty arrays (#778)
1 parent 5aa239f commit 359e287

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

octopusdeploy_framework/datasource_environments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq
6969
return
7070
}
7171

72-
var mappedEnvironments []schemas.EnvironmentTypeResourceModel
72+
mappedEnvironments := []schemas.EnvironmentTypeResourceModel{}
7373
if data.Name.IsNull() {
7474
tflog.Debug(ctx, fmt.Sprintf("environments returned from API: %#v", existingEnvironments))
7575
for _, environment := range existingEnvironments.Items {

octopusdeploy_framework/datasource_project_groups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (p *projectGroupsDataSource) Read(ctx context.Context, req datasource.ReadR
9090
return
9191
}
9292

93-
var newGroups []schemas.ProjectGroupTypeResourceModel
93+
newGroups := []schemas.ProjectGroupTypeResourceModel{}
9494
for _, projectGroup := range existingProjectGroups.Items {
9595
tflog.Debug(ctx, "loaded group "+projectGroup.Name)
9696
var g schemas.ProjectGroupTypeResourceModel

octopusdeploy_framework/datasource_spaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest,
6262
return
6363
}
6464

65-
var mappedSpaces []schemas.SpaceModel
65+
mappedSpaces := []schemas.SpaceModel{}
6666
for _, space := range existingSpaces.Items {
6767
var s schemas.SpaceModel
6868
mapSpaceToState(ctx, &s, space)

octopusdeploy_framework/datasource_tag_sets.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest
6060

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

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

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

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

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

0 commit comments

Comments
 (0)