From f54b0a88a7adaf2ad8705df7f4664018d6847c57 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Fri, 17 Mar 2017 10:08:02 -0600 Subject: [PATCH] provider/openstack: Add timeout support for Compute resources (#12794) This commit adds support for specifying timeout values for the openstack_compute_* family of resources. --- .../resource_openstack_compute_instance_v2.go | 14 +++++-- ...urce_openstack_compute_instance_v2_test.go | 30 +++++++++++++- .../resource_openstack_compute_secgroup_v2.go | 6 ++- ...urce_openstack_compute_secgroup_v2_test.go | 35 ++++++++++++++++ ...urce_openstack_compute_volume_attach_v2.go | 9 ++++- ...openstack_compute_volume_attach_v2_test.go | 40 +++++++++++++++++++ 6 files changed, 126 insertions(+), 8 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index c08d2418bc..1fa514c29d 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -34,6 +34,12 @@ func resourceComputeInstanceV2() *schema.Resource { Update: resourceComputeInstanceV2Update, Delete: resourceComputeInstanceV2Delete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -457,7 +463,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e Pending: []string{"BUILD"}, Target: []string{"ACTIVE"}, Refresh: ServerV2StateRefreshFunc(computeClient, server.ID), - Timeout: 30 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -808,7 +814,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e Pending: []string{"RESIZE"}, Target: []string{"VERIFY_RESIZE"}, Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()), - Timeout: 30 * time.Minute, + Timeout: d.Timeout(schema.TimeoutUpdate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -829,7 +835,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e Pending: []string{"VERIFY_RESIZE"}, Target: []string{"ACTIVE"}, Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()), - Timeout: 30 * time.Minute, + Timeout: d.Timeout(schema.TimeoutUpdate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } @@ -908,7 +914,7 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e Pending: []string{"ACTIVE", "SHUTOFF"}, Target: []string{"DELETED"}, Refresh: ServerV2StateRefreshFunc(computeClient, d.Id()), - Timeout: 30 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go index 324d12bbf8..cfe807e4f2 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go @@ -639,6 +639,23 @@ func TestAccComputeV2Instance_forceDelete(t *testing.T) { }) } +func TestAccComputeV2Instance_timeout(t *testing.T) { + var instance servers.Server + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeV2Instance_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), + ), + }, + }, + }) +} + func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) computeClient, err := config.computeV2Client(OS_REGION_NAME) @@ -1537,6 +1554,17 @@ const testAccComputeV2Instance_forceDelete = ` resource "openstack_compute_instance_v2" "instance_1" { name = "instance_1" security_groups = ["default"] - force_delete = true + force_delete = true +} +` + +const testAccComputeV2Instance_timeout = ` +resource "openstack_compute_instance_v2" "instance_1" { + name = "instance_1" + security_groups = ["default"] + + timeouts { + create = "10m" + } } ` diff --git a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go index dfedc04177..99887a2dac 100644 --- a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go @@ -24,6 +24,10 @@ func resourceComputeSecGroupV2() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -224,7 +228,7 @@ func resourceComputeSecGroupV2Delete(d *schema.ResourceData, meta interface{}) e Pending: []string{"ACTIVE"}, Target: []string{"DELETED"}, Refresh: SecGroupV2StateRefreshFunc(computeClient, d), - 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_compute_secgroup_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go index f0381e3373..f4a0d3ddc9 100644 --- a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go @@ -144,6 +144,24 @@ func TestAccComputeV2SecGroup_lowerCaseCIDR(t *testing.T) { }) } +func TestAccComputeV2SecGroup_timeout(t *testing.T) { + var secgroup secgroups.SecurityGroup + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeV2SecGroup_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.sg_1", &secgroup), + ), + }, + }, + }) +} + func testAccCheckComputeV2SecGroupDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) computeClient, err := config.computeV2Client(OS_REGION_NAME) @@ -373,3 +391,20 @@ resource "openstack_compute_secgroup_v2" "sg_1" { } } ` + +const testAccComputeV2SecGroup_timeout = ` +resource "openstack_compute_secgroup_v2" "sg_1" { + name = "sg_1" + description = "first test security group" + rule { + from_port = 0 + to_port = 0 + ip_protocol = "icmp" + cidr = "0.0.0.0/0" + } + + timeouts { + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2.go b/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2.go index 34404ee853..1eb8506e60 100644 --- a/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2.go @@ -22,6 +22,11 @@ func resourceComputeVolumeAttachV2() *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, @@ -82,7 +87,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ Pending: []string{"ATTACHING"}, Target: []string{"ATTACHED"}, Refresh: resourceComputeVolumeAttachV2AttachFunc(computeClient, instanceId, attachment.ID), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 30 * time.Second, MinTimeout: 15 * time.Second, } @@ -145,7 +150,7 @@ func resourceComputeVolumeAttachV2Delete(d *schema.ResourceData, meta interface{ Pending: []string{""}, Target: []string{"DETACHED"}, Refresh: resourceComputeVolumeAttachV2DetachFunc(computeClient, instanceId, attachmentId), - Timeout: 10 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 15 * time.Second, MinTimeout: 15 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2_test.go index a32e3ad3df..fb5b6baa38 100644 --- a/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_volume_attach_v2_test.go @@ -47,6 +47,24 @@ func TestAccComputeV2VolumeAttach_device(t *testing.T) { }) } +func TestAccComputeV2VolumeAttach_timeout(t *testing.T) { + var va volumeattach.VolumeAttachment + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeV2VolumeAttach_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeV2VolumeAttachExists("openstack_compute_volume_attach_v2.va_1", &va), + ), + }, + }, + }) +} + func testAccCheckComputeV2VolumeAttachDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) computeClient, err := config.computeV2Client(OS_REGION_NAME) @@ -156,3 +174,25 @@ resource "openstack_compute_volume_attach_v2" "va_1" { device = "/dev/vdc" } ` + +const testAccComputeV2VolumeAttach_timeout = ` +resource "openstack_blockstorage_volume_v2" "volume_1" { + name = "volume_1" + size = 1 +} + +resource "openstack_compute_instance_v2" "instance_1" { + name = "instance_1" + security_groups = ["default"] +} + +resource "openstack_compute_volume_attach_v2" "va_1" { + instance_id = "${openstack_compute_instance_v2.instance_1.id}" + volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +`