Skip to content

Commit d3c1e72

Browse files
authored
Merge pull request #81 from cloudskiff/fix_crash_for_s3_buckets
Fix crash for buckets in us-east-1
2 parents aacec19 + 1a05e3e commit d3c1e72

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

pkg/remote/aws/s3_bucket_supplier.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ func readBucketRegion(client *s3iface.S3API, name string) (string, error) {
6868
}
6969
return "", err
7070
}
71+
72+
// Buckets in Region us-east-1 have a LocationConstraint of null.
73+
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html#API_GetBucketLocation_ResponseSyntax
74+
if bucketLocationResponse.LocationConstraint == nil {
75+
return "us-east-1", err
76+
}
77+
7178
return *bucketLocationResponse.LocationConstraint, nil
7279
}
7380

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package aws_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/cloudskiff/driftctl/test/acceptance"
7+
)
8+
9+
func TestAcc_AwsS3Bucket_BucketInUsEast1(t *testing.T) {
10+
acceptance.Run(t, acceptance.AccTestCase{
11+
Path: "./testdata/acc/aws_s3_bucket",
12+
Args: []string{"scan", "--filter", "Type=='aws_s3_bucket'"},
13+
Checks: []acceptance.AccCheck{
14+
{
15+
Check: func(result *acceptance.ScanResult, stdout string, err error) {
16+
if err != nil {
17+
t.Fatal(err)
18+
}
19+
result.Equal(1, result.Summary().TotalManaged)
20+
result.Equal("aws_s3_bucket", result.Analysis.Managed()[0].TerraformType())
21+
result.Equal("foobar.driftctl-test.com", result.Analysis.Managed()[0].TerraformId())
22+
},
23+
},
24+
},
25+
})
26+
}

pkg/resource/aws/testdata/acc/aws_s3_bucket/.terraform.lock.hcl

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
terraform {
5+
required_providers {
6+
aws = {
7+
version = "~> 3.19.0"
8+
}
9+
}
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "aws_s3_bucket" "foobar" {
2+
bucket = "foobar.driftctl-test.com"
3+
}

0 commit comments

Comments
 (0)