Skip to content

Commit

Permalink
Merge pull request hashicorp#21 from Ensighten/probes-common
Browse files Browse the repository at this point in the history
ultradns: cleanup
  • Loading branch information
josephholsten committed Jun 9, 2016
2 parents 65196bf + 8d5ffa0 commit 95b032e
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 245 deletions.
67 changes: 67 additions & 0 deletions builtin/providers/ultradns/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ultradns

import (
"fmt"

"github.com/Ensighten/udnssdk"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func testAccTcpoolCheckDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*udnssdk.Client)

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

k := udnssdk.RRSetKey{
Zone: rs.Primary.Attributes["zone"],
Name: rs.Primary.Attributes["name"],
Type: rs.Primary.Attributes["type"],
}

_, err := client.RRSets.Select(k)
if err == nil {
return fmt.Errorf("Record still exists")
}
}

return nil
}

func testAccCheckUltradnsRecordExists(n string, record *udnssdk.RRSet) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]

if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}

client := testAccProvider.Meta().(*udnssdk.Client)
k := udnssdk.RRSetKey{
Zone: rs.Primary.Attributes["zone"],
Name: rs.Primary.Attributes["name"],
Type: rs.Primary.Attributes["type"],
}

foundRecord, err := client.RRSets.Select(k)

if err != nil {
return err
}

if foundRecord[0].OwnerName != rs.Primary.Attributes["hostname"] {
return fmt.Errorf("Record not found: %+v,\n %+v\n", foundRecord, rs.Primary.Attributes)
}

*record = foundRecord[0]

return nil
}
}
2 changes: 1 addition & 1 deletion builtin/providers/ultradns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Config) Client() (*udnssdk.Client, error) {
return nil, fmt.Errorf("Error setting up client: %s", err)
}

log.Printf("[INFO] UltraDNS Client configured for user: %s", client.Username)
log.Printf("[INFO] UltraDNS Client configured for user: %s", c.Username)

return client, nil
}
4 changes: 2 additions & 2 deletions builtin/providers/ultradns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"ultradns_record": resourceUltraDNSRecord(),
"ultradns_tcpool": resourceUltradnsTcpool(),
"ultradns_dirpool": resourceUltradnsDirpool(),
"ultradns_record": resourceUltradnsRecord(),
"ultradns_tcpool": resourceUltradnsTcpool(),
},

ConfigureFunc: providerConfigure,
Expand Down
84 changes: 42 additions & 42 deletions builtin/providers/ultradns/resource_ultradns_dirpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,54 @@ func TestAccUltradnsDirpool(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckUltradnsDirpoolDestroy,
CheckDestroy: testAccDirpoolCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(testAccCheckUltraDNSRecordDirpoolMinimal, domain),
Config: fmt.Sprintf(testCfgDirpoolMinimal, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckUltraDNSRecordExists("ultradns_dirpool.minimal", &record),
testAccCheckUltradnsRecordExists("ultradns_dirpool.it", &record),
// Specified
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "name", "dirpool-minimal"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "zone", domain),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "type", "A"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "ttl", "300"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "description", "Minimal directional pool"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "rdata.0.host", "192.168.0.10"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "rdata.0.all_non_configured", "true"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "zone", domain),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "name", "test-dirpool-minimal"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "type", "A"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "ttl", "300"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "description", "Minimal directional pool"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.0.host", "10.1.0.1"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.0.all_non_configured", "true"),
// Generated
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "id", "dirpool-minimal.ultradns.phinze.com"),
resource.TestCheckResourceAttr("ultradns_dirpool.minimal", "hostname", "dirpool-minimal.ultradns.phinze.com."),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "id", "test-dirpool-minimal.ultradns.phinze.com"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "hostname", "test-dirpool-minimal.ultradns.phinze.com."),
),
},
resource.TestStep{
Config: fmt.Sprintf(testAccCheckUltraDNSRecordDirpoolMaximal, domain),
Config: fmt.Sprintf(testCfgDirpoolMaximal, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckUltraDNSRecordExists("ultradns_dirpool.maximal", &record),
testAccCheckUltradnsRecordExists("ultradns_dirpool.it", &record),
// Specified
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "name", "dirpool-maximal"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "zone", domain),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "type", "A"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "ttl", "300"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "description", "Description of pool"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "conflict_resolve", "GEO"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.0.host", "1.2.3.4"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.0.all_non_configured", "true"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.1.host", "2.3.4.5"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.1.geo_info.0.name", "North America"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.2.host", "9.8.7.6"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "rdata.2.ip_info.0.name", "some Ips"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "no_response.0.geo_info.0.name", "nrGeo"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "no_response.0.ip_info.0.name", "nrIP"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "zone", domain),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "name", "test-dirpool-maximal"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "type", "A"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "ttl", "300"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "description", "Description of pool"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "conflict_resolve", "GEO"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.0.host", "10.1.1.1"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.0.all_non_configured", "true"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.1.host", "10.1.1.2"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.1.geo_info.0.name", "North America"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.2.host", "10.1.1.3"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "rdata.2.ip_info.0.name", "some Ips"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "no_response.0.geo_info.0.name", "nrGeo"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "no_response.0.ip_info.0.name", "nrIP"),
// Generated
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "id", "dirpool-maximal.ultradns.phinze.com"),
resource.TestCheckResourceAttr("ultradns_dirpool.maximal", "hostname", "dirpool-maximal.ultradns.phinze.com."),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "id", "test-dirpool-maximal.ultradns.phinze.com"),
resource.TestCheckResourceAttr("ultradns_dirpool.it", "hostname", "test-dirpool-maximal.ultradns.phinze.com."),
),
},
},
})
}

func testAccCheckUltradnsDirpoolDestroy(s *terraform.State) error {
func testAccDirpoolCheckDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*udnssdk.Client)

for _, rs := range s.RootModule().Resources {
Expand All @@ -87,38 +87,38 @@ func testAccCheckUltradnsDirpoolDestroy(s *terraform.State) error {
return nil
}

const testAccCheckUltraDNSRecordDirpoolMinimal = `
resource "ultradns_dirpool" "minimal" {
const testCfgDirpoolMinimal = `
resource "ultradns_dirpool" "it" {
zone = "%s"
name = "dirpool-minimal"
name = "test-dirpool-minimal"
type = "A"
ttl = 300
description = "Minimal directional pool"
rdata {
host = "192.168.0.10"
host = "10.1.0.1"
all_non_configured = true
}
}
`

const testAccCheckUltraDNSRecordDirpoolMaximal = `
resource "ultradns_dirpool" "maximal" {
const testCfgDirpoolMaximal = `
resource "ultradns_dirpool" "it" {
zone = "%s"
name = "dirpool-maximal"
name = "test-dirpool-maximal"
type = "A"
ttl = 300
description = "Description of pool"
conflict_resolve = "GEO"
rdata {
host = "1.2.3.4"
host = "10.1.1.1"
all_non_configured = true
}
rdata {
host = "2.3.4.5"
host = "10.1.1.2"
geo_info {
name = "North America"
Expand All @@ -132,7 +132,7 @@ resource "ultradns_dirpool" "maximal" {
}
rdata {
host = "9.8.7.6"
host = "10.1.1.3"
ip_info {
name = "some Ips"
Expand All @@ -153,7 +153,7 @@ resource "ultradns_dirpool" "maximal" {
}
# rdata {
# host = "30.40.50.60"
# host = "10.1.1.4"
#
# geo_info {
# name = "accountGeoGroup"
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/ultradns/resource_ultradns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func populateResourceDataFromRRSet(r udnssdk.RRSet, d *schema.ResourceData) erro
return nil
}

func resourceUltraDNSRecord() *schema.Resource {
func resourceUltradnsRecord() *schema.Resource {
return &schema.Resource{
Create: resourceUltraDNSRecordCreate,
Read: resourceUltraDNSRecordRead,
Expand Down
Loading

0 comments on commit 95b032e

Please sign in to comment.