Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use official Go client for DigitalOcean provider #3333

Merged
merged 1 commit into from
Oct 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions builtin/providers/digitalocean/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package digitalocean
import (
"log"

"github.com/pearkes/digitalocean"
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
)

type Config struct {
Token string
}

// Client() returns a new client for accessing digital ocean.
func (c *Config) Client() (*digitalocean.Client, error) {
client, err := digitalocean.NewClient(c.Token)
func (c *Config) Client() (*godo.Client, error) {
tokenSrc := oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: c.Token,
})

log.Printf("[INFO] DigitalOcean Client configured for URL: %s", client.URL)
client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, tokenSrc))

if err != nil {
return nil, err
}
log.Printf("[INFO] DigitalOcean Client configured for URL: %s", client.BaseURL.String())

return client, nil
}
21 changes: 11 additions & 10 deletions builtin/providers/digitalocean/resource_digitalocean_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"log"
"strings"

"github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/schema"
"github.com/pearkes/digitalocean"
)

func resourceDigitalOceanDomain() *schema.Resource {
Expand All @@ -32,30 +32,31 @@ func resourceDigitalOceanDomain() *schema.Resource {
}

func resourceDigitalOceanDomainCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*digitalocean.Client)
client := meta.(*godo.Client)

// Build up our creation options
opts := &digitalocean.CreateDomain{

opts := &godo.DomainCreateRequest{
Name: d.Get("name").(string),
IPAddress: d.Get("ip_address").(string),
}

log.Printf("[DEBUG] Domain create configuration: %#v", opts)
name, err := client.CreateDomain(opts)
domain, _, err := client.Domains.Create(opts)
if err != nil {
return fmt.Errorf("Error creating Domain: %s", err)
}

d.SetId(name)
log.Printf("[INFO] Domain Name: %s", name)
d.SetId(domain.Name)
log.Printf("[INFO] Domain Name: %s", domain.Name)

return resourceDigitalOceanDomainRead(d, meta)
}

func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*digitalocean.Client)
client := meta.(*godo.Client)

domain, err := client.RetrieveDomain(d.Id())
domain, _, err := client.Domains.Get(d.Id())
if err != nil {
// If the domain is somehow already destroyed, mark as
// successfully gone
Expand All @@ -73,10 +74,10 @@ func resourceDigitalOceanDomainRead(d *schema.ResourceData, meta interface{}) er
}

func resourceDigitalOceanDomainDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*digitalocean.Client)
client := meta.(*godo.Client)

log.Printf("[INFO] Deleting Domain: %s", d.Id())
err := client.DestroyDomain(d.Id())
_, err := client.Domains.Delete(d.Id())
if err != nil {
return fmt.Errorf("Error deleting Domain: %s", err)
}
Expand Down
20 changes: 10 additions & 10 deletions builtin/providers/digitalocean/resource_digitalocean_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"testing"

"github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/pearkes/digitalocean"
)

func TestAccDigitalOceanDomain_Basic(t *testing.T) {
var domain digitalocean.Domain
var domain godo.Domain

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -33,25 +33,25 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
}

func testAccCheckDigitalOceanDomainDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*digitalocean.Client)
client := testAccProvider.Meta().(*godo.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_domain" {
continue
}

// Try to find the domain
_, err := client.RetrieveDomain(rs.Primary.ID)
_, _, err := client.Domains.Get(rs.Primary.ID)

if err == nil {
fmt.Errorf("Domain still exists")
return fmt.Errorf("Domain still exists")
}
}

return nil
}

func testAccCheckDigitalOceanDomainAttributes(domain *digitalocean.Domain) resource.TestCheckFunc {
func testAccCheckDigitalOceanDomainAttributes(domain *godo.Domain) resource.TestCheckFunc {
return func(s *terraform.State) error {

if domain.Name != "foobar-test-terraform.com" {
Expand All @@ -62,7 +62,7 @@ func testAccCheckDigitalOceanDomainAttributes(domain *digitalocean.Domain) resou
}
}

func testAccCheckDigitalOceanDomainExists(n string, domain *digitalocean.Domain) resource.TestCheckFunc {
func testAccCheckDigitalOceanDomainExists(n string, domain *godo.Domain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]

Expand All @@ -74,9 +74,9 @@ func testAccCheckDigitalOceanDomainExists(n string, domain *digitalocean.Domain)
return fmt.Errorf("No Record ID is set")
}

client := testAccProvider.Meta().(*digitalocean.Client)
client := testAccProvider.Meta().(*godo.Client)

foundDomain, err := client.RetrieveDomain(rs.Primary.ID)
foundDomain, _, err := client.Domains.Get(rs.Primary.ID)

if err != nil {
return err
Expand All @@ -86,7 +86,7 @@ func testAccCheckDigitalOceanDomainExists(n string, domain *digitalocean.Domain)
return fmt.Errorf("Record not found")
}

*domain = foundDomain
*domain = *foundDomain

return nil
}
Expand Down
Loading