From 8eec0c896fba2582d06cd78aaf5c596a63a9732a Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 29 Oct 2015 13:33:35 +0000 Subject: [PATCH] Adding a computed ARN for the S3 Bucket as per #3666 --- builtin/providers/aws/resource_aws_s3_bucket.go | 8 ++++++++ builtin/providers/aws/resource_aws_s3_bucket_test.go | 7 +++++++ .../source/docs/providers/aws/r/s3_bucket.html.markdown | 1 + 3 files changed, 16 insertions(+) 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.