Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

fix: Ignore S3 Buckets Errors #1175

Merged
merged 4 commits into from
Jul 7, 2022
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
19 changes: 15 additions & 4 deletions resources/services/s3/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ func fetchS3BucketsWorker(ctx context.Context, meta schema.ClientMeta, buckets <
defer wg.Done()
cl := meta.(*client.Client)
for bucket := range buckets {
// always set default bucket region to us-east-1
wb := &WrappedBucket{Bucket: bucket, Region: "us-east-1"}
wb := &WrappedBucket{Bucket: bucket}
err := resolveS3BucketsAttributes(ctx, meta, wb)
if err != nil {
if !cl.IsNotFoundError(err) {
Expand All @@ -536,8 +535,8 @@ func resolveS3BucketsAttributes(ctx context.Context, meta schema.ClientMeta, res
}
return diag.WrapError(err)
}
// This is a weird corner case by AWS API https://github.com/aws/aws-sdk-net/issues/323#issuecomment-196584538
// empty output == region of the bucket is us-east-1, as we set it by default we are okay
// AWS does not specify a region if bucket is in us-east-1, so as long as no error we can assume an empty string is us-east-1
resource.Region = "us-east-1"
bbernays marked this conversation as resolved.
Show resolved Hide resolved
if output != "" {
resource.Region = output
}
Expand Down Expand Up @@ -574,6 +573,9 @@ func resolveS3BucketsAttributes(ctx context.Context, meta schema.ClientMeta, res
func fetchS3BucketGrants(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
r := parent.Item.(*WrappedBucket)
svc := meta.(*client.Client).Services().S3
if parent.Get("region").(string) == "" {
return nil
}
aclOutput, err := svc.GetBucketAcl(ctx, &s3.GetBucketAclInput{Bucket: r.Name}, func(options *s3.Options) {
options.Region = parent.Get("region").(string)
})
Expand All @@ -590,6 +592,9 @@ func fetchS3BucketCorsRules(ctx context.Context, meta schema.ClientMeta, parent
r := parent.Item.(*WrappedBucket)
c := meta.(*client.Client)
svc := c.Services().S3
if parent.Get("region").(string) == "" {
return nil
}
corsOutput, err := svc.GetBucketCors(ctx, &s3.GetBucketCorsInput{Bucket: r.Name}, func(options *s3.Options) {
options.Region = parent.Get("region").(string)
})
Expand All @@ -608,6 +613,9 @@ func fetchS3BucketEncryptionRules(ctx context.Context, meta schema.ClientMeta, p
r := parent.Item.(*WrappedBucket)
c := meta.(*client.Client)
svc := c.Services().S3
if parent.Get("region").(string) == "" {
return nil
}
aclOutput, err := svc.GetBucketEncryption(ctx, &s3.GetBucketEncryptionInput{Bucket: r.Name}, func(options *s3.Options) {
options.Region = parent.Get("region").(string)
})
Expand Down Expand Up @@ -642,6 +650,9 @@ func fetchS3BucketLifecycles(ctx context.Context, meta schema.ClientMeta, parent
r := parent.Item.(*WrappedBucket)
c := meta.(*client.Client)
svc := c.Services().S3
if parent.Get("region").(string) == "" {
return nil
}
lifecycleOutput, err := svc.GetBucketLifecycleConfiguration(ctx, &s3.GetBucketLifecycleConfigurationInput{Bucket: r.Name}, func(options *s3.Options) {
options.Region = parent.Get("region").(string)
})
Expand Down