Skip to content

Commit

Permalink
Clarify the docs, add default max keys
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Aug 1, 2019
1 parent 0ed98f4 commit 6f9ac1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 6 additions & 5 deletions aws/data_source_aws_s3_bucket_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
)

const maxS3ObjectListReqSize = 1000
const keyRequestPageSize = 1000

func dataSourceAwsS3BucketObjects() *schema.Resource {
return &schema.Resource{
Expand All @@ -36,6 +36,7 @@ func dataSourceAwsS3BucketObjects() *schema.Resource {
"max_keys": {
Type: schema.TypeInt,
Optional: true,
Default: 1000,
},
"start_after": {
Type: schema.TypeString,
Expand Down Expand Up @@ -110,14 +111,14 @@ func dataSourceAwsS3BucketObjectsRead(d *schema.ResourceData, meta interface{})
listInput.EncodingType = aws.String(s.(string))
}

// MaxKeys attribute refers to max keys returned in a single request
// "listInput.MaxKeys" refers to max keys returned in a single request
// (i.e., page size), not the total number of keys returned if you page
// through the results. This reduces # requests to fewest possible.
// through the results. "maxKeys" does refer to total keys returned.
maxKeys := -1
if max, ok := d.GetOk("max_keys"); ok {
maxKeys = max.(int)
if maxKeys > maxS3ObjectListReqSize {
listInput.MaxKeys = aws.Int64(int64(maxS3ObjectListReqSize))
if maxKeys > keyRequestPageSize {
listInput.MaxKeys = aws.Int64(int64(keyRequestPageSize))
} else {
listInput.MaxKeys = aws.Int64(int64(maxKeys))
}
Expand Down
7 changes: 5 additions & 2 deletions website/docs/d/s3_bucket_objects.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-

# Data Source: aws_s3_bucket_objects

The bucket-objects data source returns keys and other metadata about objects in an S3 bucket.
The bucket-objects data source returns keys (i.e., file names) and other metadata about objects in an S3 bucket.

## Example Usage

Expand All @@ -34,7 +34,10 @@ The following arguments are supported:
* `prefix` - (Optional) Limits results to object keys with this prefix (Default: none)
* `delimiter` - (Optional) A character used to group keys (Default: none)
* `encoding_type` - (Optional) Encodes keys using this method (Default: none; besides none, only "url" can be used)
* `max_objects` - (Optional) Maximum object keys to list (Default: all keys in the bucket)
* `max_keys` - (Optional) Maximum object keys to return or `-1` to retrieve all keys (Default: 1000)

~> **NOTE on `max_keys`:** Retrieving very large numbers of keys can adversely affect Terraform's performance.

* `start_after` - (Optional) Returns key names lexicographically after a specific object key in your bucket (Default: none; S3 lists object keys in UTF-8 character encoding in lexicographical order)
* `fetch_owner` - (Optional) Boolean specifying whether to populate the owner list (Default: false)

Expand Down

0 comments on commit 6f9ac1b

Please sign in to comment.