diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index 682999656..dac7d7689 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -28,6 +28,12 @@ func resourceAwsS3Bucket() *schema.Resource { ForceNew: true, }, + "arn": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "acl": &schema.Schema{ Type: schema.TypeString, Default: "private", @@ -376,6 +382,8 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { return err } + d.Set("arn", fmt.Sprint("arn:aws:s3:::", d.Id())) + return nil } diff --git a/builtin/providers/aws/resource_aws_s3_bucket_test.go b/builtin/providers/aws/resource_aws_s3_bucket_test.go index 862a0620f..04e2e6047 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" "reflect" + "regexp" "strconv" "testing" "time" @@ -17,6 +18,10 @@ import ( ) func TestAccAWSS3Bucket_basic(t *testing.T) { + + arnRegexp := regexp.MustCompile( + "^arn:aws:s3:::") + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -32,6 +37,8 @@ func TestAccAWSS3Bucket_basic(t *testing.T) { "aws_s3_bucket.bucket", "region", "us-west-2"), resource.TestCheckResourceAttr( "aws_s3_bucket.bucket", "website_endpoint", ""), + resource.TestMatchResourceAttr( + "aws_s3_bucket.bucket", "arn", arnRegexp), ), }, }, diff --git a/website/source/docs/providers/aws/r/s3_bucket.html.markdown b/website/source/docs/providers/aws/r/s3_bucket.html.markdown index da008053c..5ef365b7b 100644 --- a/website/source/docs/providers/aws/r/s3_bucket.html.markdown +++ b/website/source/docs/providers/aws/r/s3_bucket.html.markdown @@ -107,6 +107,7 @@ The versioning supports the following: The following attributes are exported: * `id` - The name of the bucket. +* `arn` - The ARN of the bucket. Will be of format `arn:aws:s3:::bucketname` * `hosted_zone_id` - The [Route 53 Hosted Zone ID](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region. * `region` - The AWS region this bucket resides in. * `website_endpoint` - The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.