From ae7db9359ebee01a6ea15679682788d9b8336ccd Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Thu, 24 Jul 2014 11:22:55 -0400 Subject: [PATCH] providers/dnsimple: finish update func, new lib --- .../dnsimple/resource_dnsimple_record.go | 26 ++++++++----------- .../dnsimple/resource_dnsimple_record_test.go | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/builtin/providers/dnsimple/resource_dnsimple_record.go b/builtin/providers/dnsimple/resource_dnsimple_record.go index e961a8fa7..611cc3606 100644 --- a/builtin/providers/dnsimple/resource_dnsimple_record.go +++ b/builtin/providers/dnsimple/resource_dnsimple_record.go @@ -44,7 +44,7 @@ func resource_dnsimple_record_create( rs.ID = recId log.Printf("[INFO] record ID: %s", rs.ID) - record, err := resource_dnsimple_record_retrieve(s.Attributes["domain"], s.ID, client) + record, err := resource_dnsimple_record_retrieve(rs.Attributes["domain"], rs.ID, client) if err != nil { return nil, fmt.Errorf("Couldn't find record: %s", err) } @@ -62,11 +62,6 @@ func resource_dnsimple_record_update( updateRecord := dnsimple.ChangeRecord{} - record, err := resource_dnsimple_record_retrieve(s.Attributes["domain"], s.ID, client) - if err != nil { - return nil, fmt.Errorf("Couldn't find record: %s", err) - } - if attr, ok := d.Attributes["name"]; ok { updateRecord.Name = attr.New } @@ -85,14 +80,14 @@ func resource_dnsimple_record_update( log.Printf("[DEBUG] record update configuration: %#v", updateRecord) - _, err = client.UpdateRecord(rs.Attributes["domain"], rs.ID, &updateRecord) + _, err := client.UpdateRecord(rs.Attributes["domain"], rs.ID, &updateRecord) if err != nil { - return nil, fmt.Errorf("Failed to update record: %s", err) + return rs, fmt.Errorf("Failed to update record: %s", err) } - record, err = resource_dnsimple_record_retrieve(s.Attributes["domain"], s.ID, client) + record, err := resource_dnsimple_record_retrieve(rs.Attributes["domain"], rs.ID, client) if err != nil { - return nil, fmt.Errorf("Couldn't find record: %s", err) + return rs, fmt.Errorf("Couldn't find record: %s", err) } return resource_dnsimple_record_update_state(rs, record) @@ -104,9 +99,9 @@ func resource_dnsimple_record_destroy( p := meta.(*ResourceProvider) client := p.client - log.Printf("[INFO] Deleting record: %s", s.ID) + log.Printf("[INFO] Deleting record: %s, %s", s.Attributes["domain"], s.ID) - err := client.DestroyRecord(s.ID) + err := client.DestroyRecord(s.Attributes["domain"], s.ID) if err != nil { return fmt.Errorf("Error deleting record: %s", err) @@ -121,7 +116,7 @@ func resource_dnsimple_record_refresh( p := meta.(*ResourceProvider) client := p.client - rec, err := resource_dnsimple_record_retrieve(s.Attributes["app"], s.ID, client) + rec, err := resource_dnsimple_record_retrieve(s.Attributes["domain"], s.ID, client) if err != nil { return nil, err } @@ -146,6 +141,7 @@ func resource_dnsimple_record_diff( ComputedAttrs: []string{ "priority", "domain_id", + "ttl", }, } @@ -169,10 +165,10 @@ func resource_dnsimple_record_update_state( func resource_dnsimple_record_retrieve(domain string, id string, client *dnsimple.Client) (*dnsimple.Record, error) { record, err := client.RetrieveRecord(domain, id) if err != nil { - return nil, fmt.Errorf("Error retrieving record: %s", err) + return nil, err } - return &record, nil + return record, nil } func resource_dnsimple_record_validation() *config.Validator { diff --git a/builtin/providers/dnsimple/resource_dnsimple_record_test.go b/builtin/providers/dnsimple/resource_dnsimple_record_test.go index a01a412c3..2bfba5190 100644 --- a/builtin/providers/dnsimple/resource_dnsimple_record_test.go +++ b/builtin/providers/dnsimple/resource_dnsimple_record_test.go @@ -139,7 +139,7 @@ func testAccCheckDNSimpleRecordExists(n string, record *dnsimple.Record) resourc return fmt.Errorf("Record not found") } - *record = foundRecord + *record = *foundRecord return nil }