provider/aws: Convert Route 53 Zone resource to use new awslabs/aws-sdk-go

library.

This commit updates the Route 53 Zone resource to use AWS Labs aws-sdk-go
library instead of mitchellh/goamz.

- hard code us-east-1 for Route53 region, since it's a global endpoint
- add some units test for CleanZoneID
This commit is contained in:
Clint Shryock 2015-02-12 08:48:48 -08:00
parent 8463c92102
commit 94e7723370
5 changed files with 196 additions and 72 deletions

View File

@ -12,8 +12,10 @@ import (
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/goamz/elb" "github.com/mitchellh/goamz/elb"
"github.com/mitchellh/goamz/rds" "github.com/mitchellh/goamz/rds"
"github.com/mitchellh/goamz/route53"
"github.com/mitchellh/goamz/s3" "github.com/mitchellh/goamz/s3"
awsGo "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/route53"
) )
type Config struct { type Config struct {
@ -28,7 +30,7 @@ type AWSClient struct {
autoscalingconn *autoscaling.AutoScaling autoscalingconn *autoscaling.AutoScaling
s3conn *s3.S3 s3conn *s3.S3
rdsconn *rds.Rds rdsconn *rds.Rds
route53 *route53.Route53 r53conn *route53.Route53
} }
// Client configures and returns a fully initailized AWSClient // Client configures and returns a fully initailized AWSClient
@ -62,7 +64,12 @@ func (c *Config) Client() (interface{}, error) {
log.Println("[INFO] Initializing RDS connection") log.Println("[INFO] Initializing RDS connection")
client.rdsconn = rds.New(auth, region) client.rdsconn = rds.New(auth, region)
log.Println("[INFO] Initializing Route53 connection") log.Println("[INFO] Initializing Route53 connection")
client.route53 = route53.New(auth, region) creds := awsGo.Creds(c.AccessKey, c.SecretKey, "")
// aws-sdk-go uses v4 for signing requests, which requires all global
// endpoints to use 'us-east-1'.
// See http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html
client.r53conn = route53.New(creds, "us-east-1", nil)
} }
if len(errs) > 0 { if len(errs) > 0 {

View File

@ -9,7 +9,9 @@ import (
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/route53"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/route53"
) )
func resourceAwsRoute53Record() *schema.Resource { func resourceAwsRoute53Record() *schema.Resource {
@ -57,11 +59,10 @@ func resourceAwsRoute53Record() *schema.Resource {
} }
func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).route53 conn := meta.(*AWSClient).r53conn
zone := d.Get("zone_id").(string) zone := d.Get("zone_id").(string)
zoneRecord, err := conn.GetHostedZone(zone) zoneRecord, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(zone)})
if err != nil { if err != nil {
return err return err
} }
@ -70,7 +71,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
// If it does not, add the zone name to form a fully qualified name // If it does not, add the zone name to form a fully qualified name
// and keep AWS happy. // and keep AWS happy.
recordName := d.Get("name").(string) recordName := d.Get("name").(string)
zoneName := strings.Trim(zoneRecord.HostedZone.Name, ".") zoneName := strings.Trim(*zoneRecord.HostedZone.Name, ".")
if !strings.HasSuffix(recordName, zoneName) { if !strings.HasSuffix(recordName, zoneName) {
d.Set("name", strings.Join([]string{recordName, zoneName}, ".")) d.Set("name", strings.Join([]string{recordName, zoneName}, "."))
} }
@ -84,16 +85,21 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
// Create the new records. We abuse StateChangeConf for this to // Create the new records. We abuse StateChangeConf for this to
// retry for us since Route53 sometimes returns errors about another // retry for us since Route53 sometimes returns errors about another
// operation happening at the same time. // operation happening at the same time.
req := &route53.ChangeResourceRecordSetsRequest{ changeBatch := &route53.ChangeBatch{
Comment: "Managed by Terraform", Comment: aws.String("Managed by Terraform"),
Changes: []route53.Change{ Changes: []route53.Change{
route53.Change{ route53.Change{
Action: "UPSERT", Action: aws.String("UPSERT"),
Record: *rec, ResourceRecordSet: rec,
}, },
}, },
} }
req := &route53.ChangeResourceRecordSetsRequest{
HostedZoneID: aws.String(cleanZoneID(*zoneRecord.HostedZone.ID)),
ChangeBatch: changeBatch,
}
log.Printf("[DEBUG] Creating resource records for zone: %s, name: %s", log.Printf("[DEBUG] Creating resource records for zone: %s, name: %s",
zone, d.Get("name").(string)) zone, d.Get("name").(string))
@ -103,7 +109,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
Timeout: 5 * time.Minute, Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second, MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) { Refresh: func() (interface{}, string, error) {
resp, err := conn.ChangeResourceRecordSets(zone, req) resp, err := conn.ChangeResourceRecordSets(req)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "PriorRequestNotComplete") { if strings.Contains(err.Error(), "PriorRequestNotComplete") {
// There is some pending operation, so just retry // There is some pending operation, so just retry
@ -114,7 +120,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
return nil, "failure", err return nil, "failure", err
} }
return resp.ChangeInfo, "accepted", nil return resp, "accepted", nil
}, },
} }
@ -122,7 +128,7 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
if err != nil { if err != nil {
return err return err
} }
changeInfo := respRaw.(route53.ChangeInfo) changeInfo := respRaw.(*route53.ChangeResourceRecordSetsResponse).ChangeInfo
// Generate an ID // Generate an ID
d.SetId(fmt.Sprintf("%s_%s_%s", zone, d.Get("name").(string), d.Get("type").(string))) d.SetId(fmt.Sprintf("%s_%s_%s", zone, d.Get("name").(string), d.Get("type").(string)))
@ -135,7 +141,10 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
Timeout: 10 * time.Minute, Timeout: 10 * time.Minute,
MinTimeout: 5 * time.Second, MinTimeout: 5 * time.Second,
Refresh: func() (result interface{}, state string, err error) { Refresh: func() (result interface{}, state string, err error) {
return resourceAwsRoute53Wait(conn, changeInfo.ID) changeRequest := &route53.GetChangeRequest{
ID: aws.String(cleanChangeID(*changeInfo.ID)),
}
return resourceAwsGoRoute53Wait(conn, changeRequest)
}, },
} }
_, err = wait.WaitForState() _, err = wait.WaitForState()
@ -147,31 +156,33 @@ func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) er
} }
func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).route53 conn := meta.(*AWSClient).r53conn
zone := d.Get("zone_id").(string) zone := d.Get("zone_id").(string)
lopts := &route53.ListOpts{ lopts := &route53.ListResourceRecordSetsRequest{
Name: d.Get("name").(string), HostedZoneID: aws.String(cleanZoneID(zone)),
Type: d.Get("type").(string), StartRecordName: aws.String(d.Get("name").(string)),
StartRecordType: aws.String(d.Get("type").(string)),
} }
resp, err := conn.ListResourceRecordSets(zone, lopts)
resp, err := conn.ListResourceRecordSets(lopts)
if err != nil { if err != nil {
return err return err
} }
// Scan for a matching record // Scan for a matching record
found := false found := false
for _, record := range resp.Records { for _, record := range resp.ResourceRecordSets {
if route53.FQDN(record.Name) != route53.FQDN(lopts.Name) { if FQDN(*record.Name) != FQDN(*lopts.StartRecordName) {
continue continue
} }
if strings.ToUpper(record.Type) != strings.ToUpper(lopts.Type) { if strings.ToUpper(*record.Type) != strings.ToUpper(*lopts.StartRecordType) {
continue continue
} }
found = true found = true
d.Set("records", record.Records) d.Set("records", record.ResourceRecords)
d.Set("ttl", record.TTL) d.Set("ttl", record.TTL)
break break
@ -185,7 +196,11 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro
} }
func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).route53 conn := meta.(*AWSClient).r53conn
zone := d.Get("zone_id").(string)
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s",
zone, d.Get("name").(string))
// Get the records // Get the records
rec, err := resourceAwsRoute53RecordBuildSet(d) rec, err := resourceAwsRoute53RecordBuildSet(d)
@ -194,18 +209,20 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
} }
// Create the new records // Create the new records
req := &route53.ChangeResourceRecordSetsRequest{ changeBatch := &route53.ChangeBatch{
Comment: "Deleted by Terraform", Comment: aws.String("Deleted by Terraform"),
Changes: []route53.Change{ Changes: []route53.Change{
route53.Change{ route53.Change{
Action: "DELETE", Action: aws.String("DELETE"),
Record: *rec, ResourceRecordSet: rec,
}, },
}, },
} }
zone := d.Get("zone_id").(string)
log.Printf("[DEBUG] Deleting resource records for zone: %s, name: %s", req := &route53.ChangeResourceRecordSetsRequest{
zone, d.Get("name").(string)) HostedZoneID: aws.String(cleanZoneID(zone)),
ChangeBatch: changeBatch,
}
wait := resource.StateChangeConf{ wait := resource.StateChangeConf{
Pending: []string{"rejected"}, Pending: []string{"rejected"},
@ -213,7 +230,7 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
Timeout: 5 * time.Minute, Timeout: 5 * time.Minute,
MinTimeout: 1 * time.Second, MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) { Refresh: func() (interface{}, string, error) {
_, err := conn.ChangeResourceRecordSets(zone, req) _, err := conn.ChangeResourceRecordSets(req)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "PriorRequestNotComplete") { if strings.Contains(err.Error(), "PriorRequestNotComplete") {
// There is some pending operation, so just retry // There is some pending operation, so just retry
@ -242,17 +259,26 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData) (*route53.ResourceRecordSet, error) { func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData) (*route53.ResourceRecordSet, error) {
recs := d.Get("records").(*schema.Set).List() recs := d.Get("records").(*schema.Set).List()
records := make([]string, 0, len(recs)) records := make([]route53.ResourceRecord, 0, len(recs))
for _, r := range recs { for _, r := range recs {
records = append(records, r.(string)) records = append(records, route53.ResourceRecord{Value: aws.String(r.(string))})
} }
rec := &route53.ResourceRecordSet{ rec := &route53.ResourceRecordSet{
Name: d.Get("name").(string), Name: aws.String(d.Get("name").(string)),
Type: d.Get("type").(string), Type: aws.String(d.Get("type").(string)),
TTL: d.Get("ttl").(int), TTL: aws.Long(int64(d.Get("ttl").(int))),
Records: records, ResourceRecords: records,
} }
return rec, nil return rec, nil
} }
func FQDN(name string) string {
n := len(name)
if n == 0 || name[n-1] == '.' {
return name
} else {
return name + "."
}
}

View File

@ -7,7 +7,9 @@ import (
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/route53"
"github.com/awslabs/aws-sdk-go/aws"
awsr53 "github.com/awslabs/aws-sdk-go/gen/route53"
) )
func TestAccRoute53Record(t *testing.T) { func TestAccRoute53Record(t *testing.T) {
@ -43,7 +45,7 @@ func TestAccRoute53Record_generatesSuffix(t *testing.T) {
} }
func testAccCheckRoute53RecordDestroy(s *terraform.State) error { func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).route53 conn := testAccProvider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_record" { if rs.Type != "aws_route53_record" {
continue continue
@ -54,16 +56,21 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
name := parts[1] name := parts[1]
rType := parts[2] rType := parts[2]
lopts := &route53.ListOpts{Name: name, Type: rType} lopts := &awsr53.ListResourceRecordSetsRequest{
resp, err := conn.ListResourceRecordSets(zone, lopts) HostedZoneID: aws.String(cleanZoneID(zone)),
StartRecordName: aws.String(name),
StartRecordType: aws.String(rType),
}
resp, err := conn.ListResourceRecordSets(lopts)
if err != nil { if err != nil {
return err return err
} }
if len(resp.Records) == 0 { if len(resp.ResourceRecordSets) == 0 {
return nil return nil
} }
rec := resp.Records[0] rec := resp.ResourceRecordSets[0]
if route53.FQDN(rec.Name) == route53.FQDN(name) && rec.Type == rType { if FQDN(*rec.Name) == FQDN(name) && *rec.Type == rType {
return fmt.Errorf("Record still exists: %#v", rec) return fmt.Errorf("Record still exists: %#v", rec)
} }
} }
@ -72,7 +79,7 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc { func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).route53 conn := testAccProvider.Meta().(*AWSClient).r53conn
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
@ -87,16 +94,21 @@ func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
name := parts[1] name := parts[1]
rType := parts[2] rType := parts[2]
lopts := &route53.ListOpts{Name: name, Type: rType} lopts := &awsr53.ListResourceRecordSetsRequest{
resp, err := conn.ListResourceRecordSets(zone, lopts) HostedZoneID: aws.String(cleanZoneID(zone)),
StartRecordName: aws.String(name),
StartRecordType: aws.String(rType),
}
resp, err := conn.ListResourceRecordSets(lopts)
if err != nil { if err != nil {
return err return err
} }
if len(resp.Records) == 0 { if len(resp.ResourceRecordSets) == 0 {
return fmt.Errorf("Record does not exist") return fmt.Errorf("Record does not exist")
} }
rec := resp.Records[0] rec := resp.ResourceRecordSets[0]
if route53.FQDN(rec.Name) == route53.FQDN(name) && rec.Type == rType { if FQDN(*rec.Name) == FQDN(name) && *rec.Type == rType {
return nil return nil
} }
return fmt.Errorf("Record does not exist: %#v", rec) return fmt.Errorf("Record does not exist: %#v", rec)

View File

@ -7,7 +7,9 @@ import (
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/mitchellh/goamz/route53"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/route53"
) )
func resourceAwsRoute53Zone() *schema.Resource { func resourceAwsRoute53Zone() *schema.Resource {
@ -32,20 +34,23 @@ func resourceAwsRoute53Zone() *schema.Resource {
} }
func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).route53 r53 := meta.(*AWSClient).r53conn
comment := &route53.HostedZoneConfig{Comment: aws.String("Managed by Terraform")}
req := &route53.CreateHostedZoneRequest{ req := &route53.CreateHostedZoneRequest{
Name: d.Get("name").(string), Name: aws.String(d.Get("name").(string)),
Comment: "Managed by Terraform", HostedZoneConfig: comment,
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
} }
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", req.Name)
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
resp, err := r53.CreateHostedZone(req) resp, err := r53.CreateHostedZone(req)
if err != nil { if err != nil {
return err return err
} }
// Store the zone_id // Store the zone_id
zone := route53.CleanZoneID(resp.HostedZone.ID) zone := cleanZoneID(*resp.HostedZone.ID)
d.Set("zone_id", zone) d.Set("zone_id", zone)
d.SetId(zone) d.SetId(zone)
@ -57,7 +62,10 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
Timeout: 10 * time.Minute, Timeout: 10 * time.Minute,
MinTimeout: 2 * time.Second, MinTimeout: 2 * time.Second,
Refresh: func() (result interface{}, state string, err error) { Refresh: func() (result interface{}, state string, err error) {
return resourceAwsRoute53Wait(r53, resp.ChangeInfo.ID) changeRequest := &route53.GetChangeRequest{
ID: aws.String(cleanChangeID(*resp.ChangeInfo.ID)),
}
return resourceAwsGoRoute53Wait(r53, changeRequest)
}, },
} }
_, err = wait.WaitForState() _, err = wait.WaitForState()
@ -68,9 +76,8 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
} }
func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).route53 r53 := meta.(*AWSClient).r53conn
_, err := r53.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(d.Id())})
_, err := r53.GetHostedZone(d.Id())
if err != nil { if err != nil {
// Handle a deleted zone // Handle a deleted zone
if strings.Contains(err.Error(), "404") { if strings.Contains(err.Error(), "404") {
@ -84,11 +91,11 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
} }
func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).route53 r53 := meta.(*AWSClient).r53conn
log.Printf("[DEBUG] Deleting Route53 hosted zone: %s (ID: %s)", log.Printf("[DEBUG] Deleting Route53 hosted zone: %s (ID: %s)",
d.Get("name").(string), d.Id()) d.Get("name").(string), d.Id())
_, err := r53.DeleteHostedZone(d.Id()) _, err := r53.DeleteHostedZone(&route53.DeleteHostedZoneRequest{ID: aws.String(d.Id())})
if err != nil { if err != nil {
return err return err
} }
@ -96,11 +103,29 @@ func resourceAwsRoute53ZoneDelete(d *schema.ResourceData, meta interface{}) erro
return nil return nil
} }
// resourceAwsRoute53Wait checks the status of a change func resourceAwsGoRoute53Wait(r53 *route53.Route53, ref *route53.GetChangeRequest) (result interface{}, state string, err error) {
func resourceAwsRoute53Wait(r53 *route53.Route53, ref string) (result interface{}, state string, err error) {
status, err := r53.GetChange(ref) status, err := r53.GetChange(ref)
if err != nil { if err != nil {
return nil, "UNKNOWN", err return nil, "UNKNOWN", err
} }
return true, status, nil return true, *status.ChangeInfo.Status, nil
}
// cleanChangeID is used to remove the leading /change/
func cleanChangeID(ID string) string {
return cleanPrefix(ID, "/change/")
}
// cleanZoneID is used to remove the leading /hostedzone/
func cleanZoneID(ID string) string {
return cleanPrefix(ID, "/hostedzone/")
}
// cleanPrefix removes a string prefix from an ID
func cleanPrefix(ID, prefix string) string {
if strings.HasPrefix(ID, prefix) {
ID = strings.TrimPrefix(ID, prefix)
}
return ID
} }

View File

@ -6,8 +6,62 @@ import (
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/gen/route53"
) )
func TestCleanPrefix(t *testing.T) {
cases := []struct {
Input, Prefix, Output string
}{
{"/hostedzone/foo", "/hostedzone/", "foo"},
{"/change/foo", "/change/", "foo"},
{"/bar", "/test", "/bar"},
}
for _, tc := range cases {
actual := cleanPrefix(tc.Input, tc.Prefix)
if actual != tc.Output {
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
}
}
}
func TestCleanZoneID(t *testing.T) {
cases := []struct {
Input, Output string
}{
{"/hostedzone/foo", "foo"},
{"/change/foo", "/change/foo"},
{"/bar", "/bar"},
}
for _, tc := range cases {
actual := cleanZoneID(tc.Input)
if actual != tc.Output {
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
}
}
}
func TestCleanChangeID(t *testing.T) {
cases := []struct {
Input, Output string
}{
{"/hostedzone/foo", "/hostedzone/foo"},
{"/change/foo", "foo"},
{"/bar", "/bar"},
}
for _, tc := range cases {
actual := cleanChangeID(tc.Input)
if actual != tc.Output {
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
}
}
}
func TestAccRoute53Zone(t *testing.T) { func TestAccRoute53Zone(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -25,13 +79,13 @@ func TestAccRoute53Zone(t *testing.T) {
} }
func testAccCheckRoute53ZoneDestroy(s *terraform.State) error { func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).route53 conn := testAccProvider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_zone" { if rs.Type != "aws_route53_zone" {
continue continue
} }
_, err := conn.GetHostedZone(rs.Primary.ID) _, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
if err == nil { if err == nil {
return fmt.Errorf("Hosted zone still exists") return fmt.Errorf("Hosted zone still exists")
} }
@ -50,8 +104,8 @@ func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
return fmt.Errorf("No hosted zone ID is set") return fmt.Errorf("No hosted zone ID is set")
} }
conn := testAccProvider.Meta().(*AWSClient).route53 conn := testAccProvider.Meta().(*AWSClient).r53conn
_, err := conn.GetHostedZone(rs.Primary.ID) _, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
if err != nil { if err != nil {
return fmt.Errorf("Hosted zone err: %v", err) return fmt.Errorf("Hosted zone err: %v", err)
} }