From 35edd9f64bf3c2895db9d01c75d3c0cd0dd97f6e Mon Sep 17 00:00:00 2001 From: Joseph Anthony Pasquale Holsten Date: Wed, 8 Jun 2016 15:22:02 -0700 Subject: [PATCH 1/3] ultradns: cleanup testing --- builtin/providers/ultradns/common_test.go | 67 ++++++++ .../resource_ultradns_dirpool_test.go | 84 ++++----- .../ultradns/resource_ultradns_record_test.go | 134 +++------------ .../ultradns/resource_ultradns_tcpool_test.go | 160 ++++++++---------- 4 files changed, 204 insertions(+), 241 deletions(-) create mode 100644 builtin/providers/ultradns/common_test.go diff --git a/builtin/providers/ultradns/common_test.go b/builtin/providers/ultradns/common_test.go new file mode 100644 index 000000000000..24470e0d3578 --- /dev/null +++ b/builtin/providers/ultradns/common_test.go @@ -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 + } +} diff --git a/builtin/providers/ultradns/resource_ultradns_dirpool_test.go b/builtin/providers/ultradns/resource_ultradns_dirpool_test.go index 82377cc297ca..dfd21b81b542 100644 --- a/builtin/providers/ultradns/resource_ultradns_dirpool_test.go +++ b/builtin/providers/ultradns/resource_ultradns_dirpool_test.go @@ -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 { @@ -87,25 +87,25 @@ 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" @@ -113,12 +113,12 @@ resource "ultradns_dirpool" "maximal" { 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" @@ -132,7 +132,7 @@ resource "ultradns_dirpool" "maximal" { } rdata { - host = "9.8.7.6" + host = "10.1.1.3" ip_info { name = "some Ips" @@ -153,7 +153,7 @@ resource "ultradns_dirpool" "maximal" { } # rdata { -# host = "30.40.50.60" +# host = "10.1.1.4" # # geo_info { # name = "accountGeoGroup" diff --git a/builtin/providers/ultradns/resource_ultradns_record_test.go b/builtin/providers/ultradns/resource_ultradns_record_test.go index f8b3de8b859a..257e7e5b4af5 100644 --- a/builtin/providers/ultradns/resource_ultradns_record_test.go +++ b/builtin/providers/ultradns/resource_ultradns_record_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccUltraDNSRecord_Basic(t *testing.T) { +func TestAccUltradnsRecord(t *testing.T) { var record udnssdk.RRSet // domain := os.Getenv("ULTRADNS_DOMAIN") domain := "ultradns.phinze.com" @@ -17,65 +17,40 @@ func TestAccUltraDNSRecord_Basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckUltraDNSRecordDestroy, + CheckDestroy: testAccRecordCheckDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccCheckUltraDNSRecordConfigBasic, domain), + Config: fmt.Sprintf(testCfgRecordMinimal, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckUltraDNSRecordExists("ultradns_record.basic", &record), - testAccCheckUltraDNSRecordAttributes(&record), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "name", "basic"), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "zone", domain), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "rdata.0", "192.168.0.10"), + testAccCheckUltradnsRecordExists("ultradns_record.it", &record), + resource.TestCheckResourceAttr("ultradns_record.it", "zone", domain), + resource.TestCheckResourceAttr("ultradns_record.it", "name", "test-record"), + resource.TestCheckResourceAttr("ultradns_record.it", "rdata.0", "10.5.0.1"), ), }, - }, - }) -} - -func TestAccUltraDNSRecord_Updated(t *testing.T) { - var record udnssdk.RRSet - domain := "ultradns.phinze.com" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckUltraDNSRecordDestroy, - Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccCheckUltraDNSRecordConfigBasic, domain), + Config: fmt.Sprintf(testCfgRecordMinimal, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckUltraDNSRecordExists("ultradns_record.basic", &record), - testAccCheckUltraDNSRecordAttributes(&record), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "name", "basic"), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "zone", domain), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "rdata.0", "192.168.0.10"), + testAccCheckUltradnsRecordExists("ultradns_record.it", &record), + resource.TestCheckResourceAttr("ultradns_record.it", "zone", domain), + resource.TestCheckResourceAttr("ultradns_record.it", "name", "test-record"), + resource.TestCheckResourceAttr("ultradns_record.it", "rdata.0", "10.5.0.1"), ), }, resource.TestStep{ - Config: fmt.Sprintf(testAccCheckUltraDNSRecordConfigNewValue, domain), + Config: fmt.Sprintf(testCfgRecordUpdated, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckUltraDNSRecordExists("ultradns_record.basic", &record), - testAccCheckUltraDNSRecordAttributesUpdated(&record), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "name", "basic"), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "zone", domain), - resource.TestCheckResourceAttr( - "ultradns_record.basic", "rdata.0", "192.168.0.11"), + testAccCheckUltradnsRecordExists("ultradns_record.it", &record), + resource.TestCheckResourceAttr("ultradns_record.it", "zone", domain), + resource.TestCheckResourceAttr("ultradns_record.it", "name", "test-record"), + resource.TestCheckResourceAttr("ultradns_record.it", "rdata.0", "10.5.0.2"), ), }, }, }) } -func testAccCheckUltraDNSRecordDestroy(s *terraform.State) error { +func testAccRecordCheckDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*udnssdk.Client) for _, rs := range s.RootModule().Resources { @@ -99,80 +74,23 @@ func testAccCheckUltraDNSRecordDestroy(s *terraform.State) error { return nil } -func testAccCheckUltraDNSRecordAttributes(record *udnssdk.RRSet) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if record.RData[0] != "192.168.0.10" { - return fmt.Errorf("Bad content: %v", record.RData) - } - - return nil - } -} - -func testAccCheckUltraDNSRecordAttributesUpdated(record *udnssdk.RRSet) resource.TestCheckFunc { - return func(s *terraform.State) error { - - if record.RData[0] != "192.168.0.11" { - return fmt.Errorf("Bad content: %v", record.RData) - } - - 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 - } -} - -const testAccCheckUltraDNSRecordConfigBasic = ` -resource "ultradns_record" "basic" { +const testCfgRecordMinimal = ` +resource "ultradns_record" "it" { zone = "%s" + name = "test-record" - name = "basic" - rdata = ["192.168.0.10"] + rdata = ["10.5.0.1"] type = "A" ttl = 3600 } ` -const testAccCheckUltraDNSRecordConfigNewValue = ` -resource "ultradns_record" "basic" { +const testCfgRecordUpdated = ` +resource "ultradns_record" "it" { zone = "%s" - name = "basic" + name = "test-record" - rdata = ["192.168.0.11"] + rdata = ["10.5.0.2"] type = "A" ttl = 3600 } diff --git a/builtin/providers/ultradns/resource_ultradns_tcpool_test.go b/builtin/providers/ultradns/resource_ultradns_tcpool_test.go index 916487610c31..ca8440040b6f 100644 --- a/builtin/providers/ultradns/resource_ultradns_tcpool_test.go +++ b/builtin/providers/ultradns/resource_ultradns_tcpool_test.go @@ -6,7 +6,6 @@ import ( "github.com/Ensighten/udnssdk" "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" ) func TestAccUltradnsTcpool(t *testing.T) { @@ -16,120 +15,96 @@ func TestAccUltradnsTcpool(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testAccCheckUltradnsTcpoolDestroy, + CheckDestroy: testAccTcpoolCheckDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccCheckUltraDNSRecordTcpoolMinimal, domain), + Config: fmt.Sprintf(testCfgTcpoolMinimal, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckUltraDNSRecordExists("ultradns_tcpool.minimal", &record), + testAccCheckUltradnsRecordExists("ultradns_tcpool.it", &record), // Specified - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "name", "tcpool-minimal"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "zone", domain), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "ttl", "300"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.host", "192.168.0.10"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "zone", domain), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "name", "test-tcpool-minimal"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "ttl", "300"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.host", "10.6.0.1"), // Defaults - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "act_on_probes", "true"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "description", "Minimal TC Pool"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "max_to_lb", "0"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "run_probes", "true"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.failover_delay", "0"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.priority", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.run_probes", "true"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.state", "NORMAL"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.threshold", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "rdata.0.weight", "2"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "act_on_probes", "true"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "description", "Minimal TC Pool"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "max_to_lb", "0"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "run_probes", "true"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.failover_delay", "0"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.priority", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.run_probes", "true"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.state", "NORMAL"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.threshold", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.weight", "2"), // Generated - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "id", "tcpool-minimal.ultradns.phinze.com"), - resource.TestCheckResourceAttr("ultradns_tcpool.minimal", "hostname", "tcpool-minimal.ultradns.phinze.com."), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "id", "test-tcpool-minimal.ultradns.phinze.com"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "hostname", "test-tcpool-minimal.ultradns.phinze.com."), ), }, resource.TestStep{ - Config: fmt.Sprintf(testAccCheckUltraDNSRecordTcpoolMaximal, domain), + Config: fmt.Sprintf(testCfgTcpoolMaximal, domain), Check: resource.ComposeTestCheckFunc( - testAccCheckUltraDNSRecordExists("ultradns_tcpool.maximal", &record), + testAccCheckUltradnsRecordExists("ultradns_tcpool.it", &record), // Specified - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "name", "tcpool-maximal"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "zone", domain), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "ttl", "300"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "description", "traffic controller pool with all settings tuned"), - - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "act_on_probes", "false"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "max_to_lb", "2"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "run_probes", "false"), - - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.host", "192.168.0.10"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.failover_delay", "30"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.priority", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.run_probes", "true"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.state", "ACTIVE"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.threshold", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.0.weight", "2"), - - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.host", "192.168.0.11"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.failover_delay", "30"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.priority", "2"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.run_probes", "true"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.state", "INACTIVE"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.threshold", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.1.weight", "4"), - - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.host", "192.168.0.12"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.failover_delay", "30"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.priority", "3"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.run_probes", "false"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.state", "NORMAL"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.threshold", "1"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "rdata.2.weight", "8"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "zone", domain), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "name", "test-tcpool-maximal"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "ttl", "300"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "description", "traffic controller pool with all settings tuned"), + + resource.TestCheckResourceAttr("ultradns_tcpool.it", "act_on_probes", "false"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "max_to_lb", "2"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "run_probes", "false"), + + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.host", "10.6.1.1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.failover_delay", "30"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.priority", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.run_probes", "true"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.state", "ACTIVE"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.threshold", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.0.weight", "2"), + + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.host", "10.6.1.2"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.failover_delay", "30"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.priority", "2"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.run_probes", "true"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.state", "INACTIVE"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.threshold", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.1.weight", "4"), + + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.host", "10.6.1.3"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.failover_delay", "30"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.priority", "3"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.run_probes", "false"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.state", "NORMAL"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.threshold", "1"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "rdata.2.weight", "8"), // Generated - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "id", "tcpool-maximal.ultradns.phinze.com"), - resource.TestCheckResourceAttr("ultradns_tcpool.maximal", "hostname", "tcpool-maximal.ultradns.phinze.com."), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "id", "test-tcpool-maximal.ultradns.phinze.com"), + resource.TestCheckResourceAttr("ultradns_tcpool.it", "hostname", "test-tcpool-maximal.ultradns.phinze.com."), ), }, }, }) } -func testAccCheckUltradnsTcpoolDestroy(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 -} - -const testAccCheckUltraDNSRecordTcpoolMinimal = ` -resource "ultradns_tcpool" "minimal" { +const testCfgTcpoolMinimal = ` +resource "ultradns_tcpool" "it" { zone = "%s" - name = "tcpool-minimal" + name = "test-tcpool-minimal" ttl = 300 description = "Minimal TC Pool" rdata { - host = "192.168.0.10" + host = "10.6.0.1" } } ` -const testAccCheckUltraDNSRecordTcpoolMaximal = ` -resource "ultradns_tcpool" "maximal" { +const testCfgTcpoolMaximal = ` +resource "ultradns_tcpool" "it" { zone = "%s" - name = "tcpool-maximal" + name = "test-tcpool-maximal" ttl = 300 description = "traffic controller pool with all settings tuned" @@ -138,7 +113,8 @@ resource "ultradns_tcpool" "maximal" { run_probes = false rdata { - host = "192.168.0.10" + host = "10.6.1.1" + failover_delay = 30 priority = 1 run_probes = true @@ -148,7 +124,8 @@ resource "ultradns_tcpool" "maximal" { } rdata { - host = "192.168.0.11" + host = "10.6.1.2" + failover_delay = 30 priority = 2 run_probes = true @@ -158,7 +135,8 @@ resource "ultradns_tcpool" "maximal" { } rdata { - host = "192.168.0.12" + host = "10.6.1.3" + failover_delay = 30 priority = 3 run_probes = false @@ -167,7 +145,7 @@ resource "ultradns_tcpool" "maximal" { weight = 8 } - backup_record_rdata = "192.168.0.11" + backup_record_rdata = "10.6.1.4" backup_record_failover_delay = 30 } ` From 6706da30e2fb01e7714d98c3e883d4da5d7089c5 Mon Sep 17 00:00:00 2001 From: Joseph Anthony Pasquale Holsten Date: Wed, 8 Jun 2016 15:22:02 -0700 Subject: [PATCH 2/3] ultradns_record: rename resource --- builtin/providers/ultradns/provider.go | 4 ++-- builtin/providers/ultradns/resource_ultradns_record.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/providers/ultradns/provider.go b/builtin/providers/ultradns/provider.go index 795407e20362..6879673eb1bc 100644 --- a/builtin/providers/ultradns/provider.go +++ b/builtin/providers/ultradns/provider.go @@ -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, diff --git a/builtin/providers/ultradns/resource_ultradns_record.go b/builtin/providers/ultradns/resource_ultradns_record.go index a87a3ef2ccba..65cd1719d3c8 100644 --- a/builtin/providers/ultradns/resource_ultradns_record.go +++ b/builtin/providers/ultradns/resource_ultradns_record.go @@ -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, From 8d5ffa08305e29d640d75749937d55624da9aa53 Mon Sep 17 00:00:00 2001 From: Joseph Anthony Pasquale Holsten Date: Wed, 8 Jun 2016 15:22:02 -0700 Subject: [PATCH 3/3] ultradns: log username from config, not client udnssdk.Client is being refactored to use x/oauth2, so don't assume we can access Username from it --- builtin/providers/ultradns/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/ultradns/config.go b/builtin/providers/ultradns/config.go index a702f421efec..d3b22d61869a 100644 --- a/builtin/providers/ultradns/config.go +++ b/builtin/providers/ultradns/config.go @@ -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 }