Skip to content

Commit

Permalink
Merge pull request #3685 from stack72/f-aws-s3bucket-arn
Browse files Browse the repository at this point in the history
Adding a computed ARN for the S3 Bucket as per #3666
  • Loading branch information
catsby committed Oct 29, 2015
2 parents 0961f5c + 8eec0c8 commit cc0b941
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions builtin/providers/aws/resource_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"reflect"
"regexp"
"strconv"
"testing"
"time"
Expand All @@ -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,
Expand All @@ -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),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cc0b941

Please sign in to comment.