Skip to content

Commit

Permalink
Add website_domain for S3 buckets.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrengelman committed Jun 3, 2015
1 parent f1439e6 commit 49d962d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
42 changes: 42 additions & 0 deletions builtin/providers/aws/resource_aws_route53_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ func TestAccRoute53Record_alias(t *testing.T) {
})
}

func TestAccRoute53Record_s3_alias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53RecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRoute53S3AliasRecord,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53RecordExists("aws_route53_record.alias"),
),
},
},
})
}

func TestAccRoute53Record_weighted_alias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -449,6 +465,32 @@ resource "aws_route53_record" "alias" {
}
`

const testAccRoute53S3AliasRecord = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
}
resource "aws_s3_bucket" "website" {
bucket = "website.notexample.com"
acl = "public-read"
website {
index_document = index.html
}
}
resource "aws_route53_record" "alias" {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "www"
type = "A"
alias {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "${aws_s3_bucket.website.website_domain}"
evaluate_target_health = true
}
}
`

const testAccRoute53WeightedElbAliasRecord = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
Expand Down
10 changes: 10 additions & 0 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"

Expand Down Expand Up @@ -84,6 +85,12 @@ func resourceAwsS3Bucket() *schema.Resource {
Computed: true,
},

"website_domain": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"tags": tagsSchema(),

"force_destroy": &schema.Schema{
Expand Down Expand Up @@ -244,6 +251,9 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("website_endpoint", endpoint); err != nil {
return err
}
if err := d.Set("website_domain", strings.TrimPrefix(endpoint, fmt.Sprintf("%s.", d.Id()))); err != nil {
return err
}

tagSet, err := getTagSetS3(s3conn, d.Id())
if err != nil {
Expand Down

0 comments on commit 49d962d

Please sign in to comment.