diff --git a/builtin/providers/packet/resource_packet_project_test.go b/builtin/providers/packet/resource_packet_project_test.go index ff1b45f7c..1ba91b1fa 100644 --- a/builtin/providers/packet/resource_packet_project_test.go +++ b/builtin/providers/packet/resource_packet_project_test.go @@ -38,7 +38,7 @@ func testAccCheckPacketProjectDestroy(s *terraform.State) error { continue } if _, _, err := client.Projects.Get(rs.Primary.ID); err == nil { - return fmt.Errorf("Project cstill exists") + return fmt.Errorf("Project still exists") } } diff --git a/builtin/providers/packet/resource_packet_volume_test.go b/builtin/providers/packet/resource_packet_volume_test.go index b2db4e3f0..1cf316a72 100644 --- a/builtin/providers/packet/resource_packet_volume_test.go +++ b/builtin/providers/packet/resource_packet_volume_test.go @@ -2,6 +2,7 @@ package packet import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -12,24 +13,26 @@ import ( func TestAccPacketVolume_Basic(t *testing.T) { var volume packngo.Volume + project_id := os.Getenv("PACKET_PROJECT_ID") + facility := os.Getenv("PACKET_FACILITY") + resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: testAccPacketVolumePreCheck(t), Providers: testAccProviders, CheckDestroy: testAccCheckPacketVolumeDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccCheckPacketVolumeConfig_basic, + Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, project_id, facility), Check: resource.ComposeTestCheckFunc( testAccCheckPacketVolumeExists("packet_volume.foobar", &volume), - testAccCheckPacketVolumeAttributes(&volume), resource.TestCheckResourceAttr( - "packet_volume.foobar", "project_id", "foobar"), + "packet_volume.foobar", "project_id", project_id), resource.TestCheckResourceAttr( - "packet_volume.foobar", "plan", "foobar"), - resource.TestCheckResourceAttr( - "packet_volume.foobar", "facility", "foobar"), + "packet_volume.foobar", "plan", "storage_1"), resource.TestCheckResourceAttr( "packet_volume.foobar", "billing_cycle", "hourly"), + resource.TestCheckResourceAttr( + "packet_volume.foobar", "size", "100"), ), }, }, @@ -44,22 +47,13 @@ func testAccCheckPacketVolumeDestroy(s *terraform.State) error { continue } if _, _, err := client.Volumes.Get(rs.Primary.ID); err == nil { - return fmt.Errorf("Volume cstill exists") + return fmt.Errorf("Volume still exists") } } return nil } -func testAccCheckPacketVolumeAttributes(volume *packngo.Volume) resource.TestCheckFunc { - return func(s *terraform.State) error { - if volume.Name != "foobar" { - return fmt.Errorf("Bad name: %s", volume.Name) - } - return nil - } -} - func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -86,10 +80,23 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T } } -var testAccCheckPacketVolumeConfig_basic = fmt.Sprintf(` +func testAccPacketVolumePreCheck(t *testing.T) func() { + return func() { + testAccPreCheck(t) + if os.Getenv("PACKET_PROJECT_ID") == "" { + t.Fatal("PACKET_PROJECT_ID must be set") + } + if os.Getenv("PACKET_FACILITY") == "" { + t.Fatal("PACKET_FACILITY must be set") + } + } +} + +const testAccCheckPacketVolumeConfig_basic = ` resource "packet_volume" "foobar" { - project_id = "foobar" - plan = "foobar" - facility = "foobar" + plan = "storage_1" billing_cycle = "hourly" -}`) + size = 100 + project_id = "%s" + facility = "%s" +}` diff --git a/vendor/github.com/packethost/packngo/volumes.go b/vendor/github.com/packethost/packngo/volumes.go index 6a7037826..c3c3e561b 100644 --- a/vendor/github.com/packethost/packngo/volumes.go +++ b/vendor/github.com/packethost/packngo/volumes.go @@ -82,7 +82,7 @@ type VolumeServiceOp struct { // Get returns a volume by id func (v *VolumeServiceOp) Get(volumeID string) (*Volume, *Response, error) { - path := fmt.Sprintf("%s/%s", volumeBasePath, volumeID) + path := fmt.Sprintf("%s/%s?include=facility", volumeBasePath, volumeID) req, err := v.client.NewRequest("GET", path, nil) if err != nil { return nil, nil, err