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

US GovCloud S3 sweeper fixes #34818

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/service/s3/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func sweepObjects(region string) error {

if awsv2.SkipSweepError(err) {
log.Printf("[WARN] Skipping S3 Objects sweep for %s: %s", region, err)
return nil
break // Allow objects in general purpose buckets to be deleted.
}

if err != nil {
Expand Down Expand Up @@ -138,10 +138,12 @@ type objectSweeper struct {

func (os objectSweeper) Delete(ctx context.Context, timeout time.Duration, optFns ...tfresource.OptionsFunc) error {
// Delete everything including locked objects.
_, err := emptyBucket(ctx, os.conn, os.bucket, os.locked)
log.Printf("[INFO] Emptying S3 Bucket (%s)", os.bucket)
n, err := emptyBucket(ctx, os.conn, os.bucket, os.locked)
if err != nil {
return fmt.Errorf("deleting S3 Bucket (%s) objects: %w", os.bucket, err)
}
log.Printf("[INFO] Deleted %d S3 Objects from S3 Bucket (%s)", n, os.bucket)
return nil
}

Expand All @@ -151,10 +153,12 @@ type directoryBucketObjectSweeper struct {
}

func (os directoryBucketObjectSweeper) Delete(ctx context.Context, timeout time.Duration, optFns ...tfresource.OptionsFunc) error {
_, err := emptyDirectoryBucket(ctx, os.conn, os.bucket)
log.Printf("[INFO] Emptying S3 Directory Bucket (%s)", os.bucket)
n, err := emptyDirectoryBucket(ctx, os.conn, os.bucket)
if err != nil {
return fmt.Errorf("deleting S3 Directory Bucket (%s) objects: %w", os.bucket, err)
}
log.Printf("[INFO] Deleted %d S3 Objects from S3 Directory Bucket (%s)", n, os.bucket)
return nil
}

Expand Down Expand Up @@ -231,6 +235,7 @@ func bucketNameFilter(bucket types.Bucket) bool {
"tf-test",
"tftest.applicationversion",
"terraform-remote-s3-test",
"aws-security-data-lake-", // Orphaned by aws_securitylake_data_lake.
}
for _, prefix := range prefixes {
if strings.HasPrefix(name, prefix) {
Expand Down
Loading