From e37b26a3fabd8fa42ae2cc3e749a451f6f950fc8 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sun, 19 Mar 2017 11:07:26 -0600 Subject: [PATCH] provider/openstack: Adding Timeouts to Blockstorage Resources (#12862) --- ...openstack_blockstorage_volume_attach_v2.go | 9 ++++- ...tack_blockstorage_volume_attach_v2_test.go | 40 +++++++++++++++++++ ...source_openstack_blockstorage_volume_v1.go | 9 ++++- ...e_openstack_blockstorage_volume_v1_test.go | 31 ++++++++++++++ ...source_openstack_blockstorage_volume_v2.go | 9 ++++- ...e_openstack_blockstorage_volume_v2_test.go | 31 ++++++++++++++ 6 files changed, 123 insertions(+), 6 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2.go index 94b501ef8..4dd28e7bc 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2.go @@ -19,6 +19,11 @@ func resourceBlockStorageVolumeAttachV2() *schema.Resource { Read: resourceBlockStorageVolumeAttachV2Read, Delete: resourceBlockStorageVolumeAttachV2Delete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -231,7 +236,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter Pending: []string{"available", "attaching"}, Target: []string{"in-use"}, Refresh: VolumeV2StateRefreshFunc(client, volumeId), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -369,7 +374,7 @@ func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta inter Pending: []string{"in-use", "attaching", "detaching"}, Target: []string{"available"}, Refresh: VolumeV2StateRefreshFunc(client, volumeId), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go index 53fd72fc8..d6b54c447 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go @@ -29,6 +29,24 @@ func TestAccBlockStorageVolumeAttachV2_basic(t *testing.T) { }) } +func TestAccBlockStorageVolumeAttachV2_timeout(t *testing.T) { + var va volumes.Attachment + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBlockStorageVolumeAttachV2_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckBlockStorageVolumeAttachV2Exists("openstack_blockstorage_volume_attach_v2.va_1", &va), + ), + }, + }, + }) +} + func testAccCheckBlockStorageVolumeAttachV2Destroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) client, err := config.blockStorageV2Client(OS_REGION_NAME) @@ -124,3 +142,25 @@ resource "openstack_blockstorage_volume_attach_v2" "va_1" { platform = "x86_64" } ` + +const testAccBlockStorageVolumeAttachV2_timeout = ` +resource "openstack_blockstorage_volume_v2" "volume_1" { + name = "volume_1" + size = 1 +} + +resource "openstack_blockstorage_volume_attach_v2" "va_1" { + volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}" + device = "auto" + + host_name = "devstack" + ip_address = "192.168.255.10" + initiator = "iqn.1993-08.org.debian:01:e9861fb1859" + os_type = "linux2" + platform = "x86_64" + + timeouts { + create = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go index ed3ef561d..8c84a08e8 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go @@ -24,6 +24,11 @@ func resourceBlockStorageVolumeV1() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -139,7 +144,7 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{} Pending: []string{"downloading", "creating"}, Target: []string{"available"}, Refresh: VolumeV1StateRefreshFunc(blockStorageClient, v.ID), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -278,7 +283,7 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{} Pending: []string{"deleting", "downloading", "available"}, Target: []string{"deleted"}, Refresh: VolumeV1StateRefreshFunc(blockStorageClient, d.Id()), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1_test.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1_test.go index 85d82f489..7dd16169e 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1_test.go @@ -61,6 +61,24 @@ func TestAccBlockStorageV1Volume_image(t *testing.T) { }) } +func TestAccBlockStorageV1Volume_timeout(t *testing.T) { + var volume volumes.Volume + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBlockStorageV1Volume_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.volume_1", &volume), + ), + }, + }, + }) +} + func testAccCheckBlockStorageV1VolumeDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) blockStorageClient, err := config.blockStorageV1Client(OS_REGION_NAME) @@ -188,3 +206,16 @@ resource "openstack_blockstorage_volume_v1" "volume_1" { image_id = "%s" } `, OS_IMAGE_ID) + +const testAccBlockStorageV1Volume_timeout = ` +resource "openstack_blockstorage_volume_v1" "volume_1" { + name = "volume_1" + description = "first test volume" + size = 1 + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go index 3a889c301..5944cac04 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go @@ -24,6 +24,11 @@ func resourceBlockStorageVolumeV2() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -151,7 +156,7 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{} Pending: []string{"downloading", "creating"}, Target: []string{"available"}, Refresh: VolumeV2StateRefreshFunc(blockStorageClient, v.ID), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -289,7 +294,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{} Pending: []string{"deleting", "downloading", "available"}, Target: []string{"deleted"}, Refresh: VolumeV2StateRefreshFunc(blockStorageClient, d.Id()), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2_test.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2_test.go index 43a128979..a9991a71e 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2_test.go @@ -61,6 +61,24 @@ func TestAccBlockStorageV2Volume_image(t *testing.T) { }) } +func TestAccBlockStorageV2Volume_timeout(t *testing.T) { + var volume volumes.Volume + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBlockStorageV2Volume_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckBlockStorageV2VolumeExists("openstack_blockstorage_volume_v2.volume_1", &volume), + ), + }, + }, + }) +} + func testAccCheckBlockStorageV2VolumeDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) blockStorageClient, err := config.blockStorageV2Client(OS_REGION_NAME) @@ -186,3 +204,16 @@ resource "openstack_blockstorage_volume_v2" "volume_1" { image_id = "%s" } `, OS_IMAGE_ID) + +const testAccBlockStorageV2Volume_timeout = ` +resource "openstack_blockstorage_volume_v2" "volume_1" { + name = "volume_1" + description = "first test volume" + size = 1 + + timeouts { + create = "5m" + delete = "5m" + } +} +`