Skip to content

Commit

Permalink
Workaround AWS S3 bucket region conflicts in acc tests.
Browse files Browse the repository at this point in the history
HeadBucket and GetBucketReplication calls will fail on us-west-2 region
when accessing a bucket on eu-west-1 region. Since we do not know which
provider is which, make sure we do fail on these region conflicts.
  • Loading branch information
modax committed Dec 18, 2017
1 parent 70e076e commit 55a00de
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,20 @@ func testAccCheckAWSS3BucketExistsWithProviders(n string, providers *[]*schema.P
Bucket: aws.String(rs.Primary.ID),
})

// Bucket will be found in one of providers only. Head bucket may fail with this
// so just continue with another provider
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "BucketRegionError" {
continue
}

if err != nil {
return fmt.Errorf("S3Bucket error: %v", err)
}

return nil
}

return fmt.Errorf("Instance not found")
return fmt.Errorf("%s: bucket %s not found", n, rs.Primary.ID)
}
}

Expand Down Expand Up @@ -1300,6 +1307,11 @@ func testAccCheckAWSS3BucketReplicationRules(n string, providers *[]*schema.Prov
Bucket: aws.String(rs.Primary.ID),
})
if err != nil {
// Bucket will be found in one of providers only. GetBucketReplication may fail with this
// so just continue with another provider then
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "BucketRegionError" {
continue
}
if rules == nil {
return nil
}
Expand All @@ -1311,7 +1323,7 @@ func testAccCheckAWSS3BucketReplicationRules(n string, providers *[]*schema.Prov

return nil
}
return fmt.Errorf("Bucket not found")
return fmt.Errorf("%s: bucket %s not found", n, rs.Primary.ID)
}
}

Expand Down

0 comments on commit 55a00de

Please sign in to comment.