From 80936e3562a5a695c767985dac121d3cc8cc60a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Sun, 26 Jun 2016 17:18:17 -0400 Subject: [PATCH] provider/triton: add machine domain names (#7149) * vendor joyent/gosdc/cloudapi * provider/triton: Add machine domain names - Includes acceptance test. --- builtin/providers/triton/resource_machine.go | 9 ++++ .../providers/triton/resource_machine_test.go | 44 +++++++++++++++++++ helper/resource/testing.go | 20 +++++++++ .../joyent/gosdc/cloudapi/machines.go | 1 + vendor/vendor.json | 4 +- 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/builtin/providers/triton/resource_machine.go b/builtin/providers/triton/resource_machine.go index 518d4f290..2523dd5d0 100644 --- a/builtin/providers/triton/resource_machine.go +++ b/builtin/providers/triton/resource_machine.go @@ -167,6 +167,14 @@ func resourceMachine() *schema.Resource { Optional: true, Default: false, }, + "domain_names": { + Description: "list of domain names from Triton's CNS", + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, // computed resources from metadata "root_authorized_keys": { @@ -298,6 +306,7 @@ func resourceMachineRead(d *schema.ResourceData, meta interface{}) error { d.Set("image", machine.Image) d.Set("primaryip", machine.PrimaryIP) d.Set("firewall_enabled", machine.FirewallEnabled) + d.Set("domain_names", machine.DomainNames) // create and update NICs var ( diff --git a/builtin/providers/triton/resource_machine_test.go b/builtin/providers/triton/resource_machine_test.go index 2ed6dd04e..dd9ba7a00 100644 --- a/builtin/providers/triton/resource_machine_test.go +++ b/builtin/providers/triton/resource_machine_test.go @@ -2,6 +2,7 @@ package triton import ( "fmt" + "regexp" "testing" "time" @@ -34,6 +35,35 @@ func TestAccTritonMachine_basic(t *testing.T) { }) } +func TestAccTritonMachine_dns(t *testing.T) { + machineName := fmt.Sprintf("acctest-%d", acctest.RandInt()) + dns_output := fmt.Sprintf(testAccTritonMachine_dns, machineName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckTritonMachineDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: dns_output, + Check: resource.ComposeTestCheckFunc( + testCheckTritonMachineExists("triton_machine.test"), + func(*terraform.State) error { + time.Sleep(10 * time.Second) + return nil + }, + ), + }, + resource.TestStep{ + Config: dns_output, + Check: resource.TestMatchOutput( + "domain_names", regexp.MustCompile(".*acctest-.*"), + ), + }, + }, + }) +} + func TestAccTritonMachine_nic(t *testing.T) { machineName := fmt.Sprintf("acctest-%d", acctest.RandInt()) config := fmt.Sprintf(testAccTritonMachine_withnic, machineName, machineName) @@ -369,3 +399,17 @@ resource "triton_machine" "test" { } } ` + +var testAccTritonMachine_dns = ` +provider "triton" { +} + +resource "triton_machine" "test" { + name = "%s" + package = "g4-highcpu-128M" + image = "e1faace4-e19b-11e5-928b-83849e2fd94a" +} +output "domain_names" { + value = "${join(", ", triton_machine.test.domain_names)}" +} +` diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 7c4ba174b..e1f1caa9c 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -600,6 +600,26 @@ func TestCheckOutput(name, value string) TestCheckFunc { } } +func TestMatchOutput(name string, r *regexp.Regexp) TestCheckFunc { + return func(s *terraform.State) error { + ms := s.RootModule() + rs, ok := ms.Outputs[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + if !r.MatchString(rs.Value.(string)) { + return fmt.Errorf( + "Output '%s': %#v didn't match %q", + name, + rs, + r.String()) + } + + return nil + } +} + // TestT is the interface used to handle the test lifecycle of a test. // // Users should just use a *testing.T object, which implements this. diff --git a/vendor/github.com/joyent/gosdc/cloudapi/machines.go b/vendor/github.com/joyent/gosdc/cloudapi/machines.go index e89980ee4..32a3ccf65 100644 --- a/vendor/github.com/joyent/gosdc/cloudapi/machines.go +++ b/vendor/github.com/joyent/gosdc/cloudapi/machines.go @@ -30,6 +30,7 @@ type Machine struct { PrimaryIP string // The primary (public) IP address for the machine Networks []string // The network IDs for the machine FirewallEnabled bool `json:"firewall_enabled"` // whether or not the firewall is enabled + DomainNames []string `json:"dns_names"` // The domain names of this machine } // Equals compares two machines. Ignores state and timestamps. diff --git a/vendor/vendor.json b/vendor/vendor.json index 2479e2eb2..f55c8ad30 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -950,8 +950,10 @@ "revision": "ade826b8b54e81a779ccb29d358a45ba24b7809c" }, { + "checksumSHA1": "PDzjpRNeytdYU39/PByzwCMvKQ8=", "path": "github.com/joyent/gosdc/cloudapi", - "revision": "0697a5c4f39a71a4f9e3b154380b47dbfcc3da6e" + "revision": "042c6e9de2b48a646d310e70cc0050c83fe18200", + "revisionTime": "2016-04-26T05:09:12Z" }, { "checksumSHA1": "N0NRIcJF7aj1wd56DA1N9GpYq/4=",