Skip to content

Commit

Permalink
test/resource/aws_s3_bucket: Add EMR bootstrap prefix to sweeper list (
Browse files Browse the repository at this point in the history
…hashicorp#10106)

Currently the EMR cluster test configuration creates a s3 bucket that is publicly accessible. These buckets are not currently cleaned up after testing so this change updates the s3 sweeper to remove test buckets starting with the prefix `tf-emr-bootstrap`. In the long term, we should determine if EMR bootstrapping supports non-public buckets and update the test configurations with the proper bucket permissions.

Before the change:
```
> go test ./aws -v -sweep=us-gov-west-1 -sweep-run=aws_s3_bucket -timeout 10h
2019/09/13 13:22:08 [DEBUG] Running Sweepers for region (us-gov-west-1):
2019/09/13 13:22:08 [DEBUG] Sweeper (aws_s3_bucket) has dependency (aws_s3_bucket_object), running..
2019/09/13 13:22:08 [INFO] Building AWS auth structure
2019/09/13 13:22:08 [INFO] Setting AWS metadata API timeout to 100ms
2019/09/13 13:22:08 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
...
2019/09/13 13:22:11 [INFO] Skipping S3 Bucket: tf-emr-bootstrap-396768694530128871
...
2019/09/13 13:22:13 [DEBUG] Sweeper (aws_s3_bucket_object) already ran in region (us-gov-west-1)
2019/09/13 13:22:13 Sweeper Tests ran:
	- aws_s3_bucket_object
	- aws_s3_bucket
ok  	github.com/terraform-providers/terraform-provider-aws/aws	5.138s
```

After the change
```
> go test ./aws -v -sweep=us-gov-west-1 -sweep-run=aws_s3_bucket -timeout 10h
2019/09/13 13:34:30 [DEBUG] Running Sweepers for region (us-gov-west-1):
2019/09/13 13:34:30 [DEBUG] Sweeper (aws_s3_bucket) has dependency (aws_s3_bucket_object), running..
2019/09/13 13:34:30 [INFO] Building AWS auth structure
2019/09/13 13:34:30 [INFO] Setting AWS metadata API timeout to 100ms
2019/09/13 13:34:30 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id
...
2019/09/13 13:34:33 [INFO] Deleting S3 Bucket (tf-emr-bootstrap-396768694530128871) Object (testscript.sh) Version: null
...
2019/09/13 13:34:38 [DEBUG] Sweeper (aws_s3_bucket_object) already ran in region (us-gov-west-1)
2019/09/13 13:34:38 Sweeper Tests ran:
	- aws_s3_bucket_object
	- aws_s3_bucket
ok  	github.com/terraform-providers/terraform-provider-aws/aws	8.158s
```
  • Loading branch information
nywilken authored Sep 24, 2019
1 parent ae3c8c5 commit 6fe866b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_s3_bucket_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func testSweepS3BucketObjects(region string) error {
bucketName := aws.StringValue(bucket.Name)

hasPrefix := false
prefixes := []string{"mybucket.", "mylogs.", "tf-acc", "tf-object-test", "tf-test"}
prefixes := []string{"mybucket.", "mylogs.", "tf-acc", "tf-object-test", "tf-test", "tf-emr-bootstrap"}

for _, prefix := range prefixes {
if strings.HasPrefix(bucketName, prefix) {
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testSweepS3Buckets(region string) error {
name := aws.StringValue(bucket.Name)

hasPrefix := false
prefixes := []string{"mybucket.", "mylogs.", "tf-acc", "tf-object-test", "tf-test"}
prefixes := []string{"mybucket.", "mylogs.", "tf-acc", "tf-object-test", "tf-test", "tf-emr-bootstrap"}

for _, prefix := range prefixes {
if strings.HasPrefix(name, prefix) {
Expand Down

0 comments on commit 6fe866b

Please sign in to comment.