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 1551e59
Showing 1 changed file with 10 additions and 7 deletions.
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 1551e59

Please sign in to comment.