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

feat: allow more than 1000 state files #223

Merged
merged 3 commits into from Feb 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions state/aws.go
Expand Up @@ -135,25 +135,33 @@ func (a *AWS) GetLocks() (locks map[string]LockInfo, err error) {

// GetStates returns a slice of State files in the S3 bucket
func (a *AWS) GetStates() (states []string, err error) {
truncatedListing := true
var keys []string
log.WithFields(log.Fields{
"bucket": a.bucket,
"prefix": a.keyPrefix,
}).Debug("Listing states from S3")
result, err := a.svc.ListObjects(&s3.ListObjectsInput{

params := s3.ListObjectsV2Input{
Bucket: aws_sdk.String(a.bucket),
Prefix: &a.keyPrefix,
})
if err != nil {
return states, err
}
for truncatedListing {
result, err := a.svc.ListObjectsV2(&params)
if err != nil {
return states, err
}

var keys []string
for _, obj := range result.Contents {
for _, ext := range a.fileExtension {
if strings.HasSuffix(*obj.Key, ext) {
keys = append(keys, *obj.Key)
for _, obj := range result.Contents {
for _, ext := range a.fileExtension {
if strings.HasSuffix(*obj.Key, ext) {
keys = append(keys, *obj.Key)
}
}
}
params.ContinuationToken = result.NextContinuationToken
truncatedListing = *result.IsTruncated

}
states = keys
log.WithFields(log.Fields{
Expand Down