Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty datasource results should be empty arrays #778

Merged
merged 3 commits into from
Sep 10, 2024
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
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
Loading