Skip to content

Commit

Permalink
fix: Fix create timestamp cmp for aws_appstream_image data source
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Jul 27, 2024
1 parent 528314a commit 2a22a6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/38571.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_appstream_image: Fix issue where the most recent image is not returned
```
17 changes: 10 additions & 7 deletions internal/service/appstream/image_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ package appstream

import (
"context"
"sort"
"time"
"slices"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -202,15 +201,19 @@ func (d *dataSourceImage) Read(ctx context.Context, req datasource.ReadRequest,
)
return
}
sort.Slice(filteredImages, func(i, j int) bool {
itime, _ := time.Parse(time.RFC3339, images[i].CreatedTime.Month().String())
jtime, _ := time.Parse(time.RFC3339, images[j].CreatedTime.Month().String())
return itime.Unix() > jtime.Unix()
slices.SortFunc(filteredImages, func(a, b awstypes.Image) int {
if aws.ToTime(a.CreatedTime).After(aws.ToTime(b.CreatedTime)) {
return -1
}
if aws.ToTime(a.CreatedTime).Before(aws.ToTime(b.CreatedTime)) {
return 1
}
return 0
})
}
image := filteredImages[0]

data.Type = fwtypes.StringEnumValue[awstypes.VisibilityType](image.Visibility)
data.Type = fwtypes.StringEnumValue(image.Visibility)
resp.Diagnostics.Append(flex.Flatten(ctx, &image, &data)...)
if resp.Diagnostics.HasError() {
return
Expand Down

0 comments on commit 2a22a6b

Please sign in to comment.