diff --git a/builtin/providers/packet/resource_packet_volume_test.go b/builtin/providers/packet/resource_packet_volume_test.go index cffd55f13..cc487d897 100644 --- a/builtin/providers/packet/resource_packet_volume_test.go +++ b/builtin/providers/packet/resource_packet_volume_test.go @@ -2,9 +2,9 @@ package packet import ( "fmt" - "os" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/packethost/packngo" @@ -13,20 +13,17 @@ import ( func TestAccPacketVolume_Basic(t *testing.T) { var volume packngo.Volume - project_id := os.Getenv("PACKET_PROJECT_ID") - facility := os.Getenv("PACKET_FACILITY") + rs := acctest.RandString(10) resource.Test(t, resource.TestCase{ - PreCheck: testAccPacketVolumePreCheck(t), + PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckPacketVolumeDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, project_id, facility), + Config: fmt.Sprintf(testAccCheckPacketVolumeConfig_basic, rs), Check: resource.ComposeTestCheckFunc( testAccCheckPacketVolumeExists("packet_volume.foobar", &volume), - resource.TestCheckResourceAttr( - "packet_volume.foobar", "project_id", project_id), resource.TestCheckResourceAttr( "packet_volume.foobar", "plan", "storage_1"), resource.TestCheckResourceAttr( @@ -80,24 +77,16 @@ func testAccCheckPacketVolumeExists(n string, volume *packngo.Volume) resource.T } } -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_project" "foobar" { + name = "%s" } -const testAccCheckPacketVolumeConfig_basic = ` resource "packet_volume" "foobar" { plan = "storage_1" billing_cycle = "hourly" size = 100 - project_id = "%s" - facility = "%s" + project_id = "${packet_project.foobar.id}" + facility = "ewr1" snapshot_policies = { snapshot_frequency = "1day", snapshot_count = 7 } }`