providers/digitalocean: tests passing, compiling

This commit is contained in:
Mitchell Hashimoto 2014-09-16 17:28:22 -07:00
parent c2a2aca999
commit aafbc2ab7c
6 changed files with 49 additions and 52 deletions

View File

@ -35,13 +35,13 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
func testAccCheckDigitalOceanDomainDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_domain" {
continue
}
// Try to find the domain
_, err := client.RetrieveDomain(rs.ID)
_, err := client.RetrieveDomain(rs.Primary.ID)
if err == nil {
fmt.Errorf("Domain still exists")
@ -64,25 +64,25 @@ func testAccCheckDigitalOceanDomainAttributes(domain *digitalocean.Domain) resou
func testAccCheckDigitalOceanDomainExists(n string, domain *digitalocean.Domain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundDomain, err := client.RetrieveDomain(rs.ID)
foundDomain, err := client.RetrieveDomain(rs.Primary.ID)
if err != nil {
return err
}
if foundDomain.Name != rs.ID {
if foundDomain.Name != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -15,9 +15,9 @@ import (
)
func resource_digitalocean_droplet_create(
s *terraform.ResourceState,
s *terraform.InstanceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -83,16 +83,16 @@ func resource_digitalocean_droplet_create(
droplet := dropletRaw.(*digitalocean.Droplet)
// Initialize the connection info
rs.ConnInfo["type"] = "ssh"
rs.ConnInfo["host"] = droplet.IPV4Address("public")
rs.Ephemeral.ConnInfo["type"] = "ssh"
rs.Ephemeral.ConnInfo["host"] = droplet.IPV4Address("public")
return resource_digitalocean_droplet_update_state(rs, droplet)
}
func resource_digitalocean_droplet_update(
s *terraform.ResourceState,
s *terraform.InstanceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
rs := s.MergeDiff(d)
@ -193,7 +193,7 @@ func resource_digitalocean_droplet_update(
}
func resource_digitalocean_droplet_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
@ -216,8 +216,8 @@ func resource_digitalocean_droplet_destroy(
}
func resource_digitalocean_droplet_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -236,7 +236,7 @@ func resource_digitalocean_droplet_refresh(
}
func resource_digitalocean_droplet_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
@ -270,8 +270,8 @@ func resource_digitalocean_droplet_diff(
}
func resource_digitalocean_droplet_update_state(
s *terraform.ResourceState,
droplet *digitalocean.Droplet) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
droplet *digitalocean.Droplet) (*terraform.InstanceState, error) {
s.Attributes["name"] = droplet.Name
s.Attributes["region"] = droplet.RegionSlug()
@ -372,7 +372,7 @@ func new_droplet_state_refresh_func(id string, attribute string, client *digital
// Use our mapping to get back a map of the
// droplet properties
resourceMap, err := resource_digitalocean_droplet_update_state(
&terraform.ResourceState{Attributes: map[string]string{}}, &droplet)
&terraform.InstanceState{Attributes: map[string]string{}}, &droplet)
if err != nil {
log.Printf("Error creating map from droplet: %s", err)

View File

@ -96,20 +96,20 @@ func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
func testAccCheckDigitalOceanDropletDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_droplet" {
continue
}
// Try to find the Droplet
_, err := client.RetrieveDroplet(rs.ID)
_, err := client.RetrieveDroplet(rs.Primary.ID)
// Wait
if err != nil && !strings.Contains(err.Error(), "404") {
return fmt.Errorf(
"Error waiting for droplet (%s) to be destroyed: %s",
rs.ID, err)
rs.Primary.ID, err)
}
}
@ -198,24 +198,24 @@ func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *di
func testAccCheckDigitalOceanDropletExists(n string, droplet *digitalocean.Droplet) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Droplet ID is set")
}
client := testAccProvider.client
retrieveDroplet, err := client.RetrieveDroplet(rs.ID)
retrieveDroplet, err := client.RetrieveDroplet(rs.Primary.ID)
if err != nil {
return err
}
if retrieveDroplet.StringId() != rs.ID {
if retrieveDroplet.StringId() != rs.Primary.ID {
return fmt.Errorf("Droplet not found")
}
@ -230,7 +230,7 @@ func Test_new_droplet_state_refresh_func(t *testing.T) {
Name: "foobar",
}
resourceMap, _ := resource_digitalocean_droplet_update_state(
&terraform.ResourceState{Attributes: map[string]string{}}, &droplet)
&terraform.InstanceState{Attributes: map[string]string{}}, &droplet)
// See if we can access our attribute
if _, ok := resourceMap.Attributes["name"]; !ok {

View File

@ -6,7 +6,6 @@ import (
"strings"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/pearkes/digitalocean"
)
@ -152,10 +151,5 @@ func resourceRecordRead(d *schema.ResourceData, meta interface{}) error {
d.Set("priority", rec.StringPriority())
d.Set("port", rec.StringPort())
// We belong to a Domain
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("domain").(string)},
})
return nil
}

View File

@ -79,12 +79,12 @@ func TestAccDigitalOceanRecord_Updated(t *testing.T) {
func testAccCheckDigitalOceanRecordDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_record" {
continue
}
_, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
_, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Record still exists")
@ -118,25 +118,25 @@ func testAccCheckDigitalOceanRecordAttributesUpdated(record *digitalocean.Record
func testAccCheckDigitalOceanRecordExists(n string, record *digitalocean.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundRecord, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
foundRecord, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err != nil {
return err
}
if foundRecord.StringId() != rs.ID {
if foundRecord.StringId() != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -55,32 +55,35 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Apply(s, d)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.ResourceDiff) (*terraform.InstanceState, error) {
if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Apply(info, s, d)
}
return resourceMap.Apply(s, d, p)
return resourceMap.Apply(info, s, d, p)
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Diff(s, c)
if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Diff(info, s, c)
}
return resourceMap.Diff(s, c, p)
return resourceMap.Diff(info, s, c, p)
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Refresh(s)
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Refresh(info, s)
}
return resourceMap.Refresh(s, p)
return resourceMap.Refresh(info, s, p)
}
func (p *ResourceProvider) Resources() []terraform.ResourceType {