From 6b6a18a0e2e2d14e409f9671ccda17614777913f Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sun, 19 Mar 2017 16:13:58 +0000 Subject: [PATCH] provider/openstack: Adding Timeouts to Image v2 and LBaaS v2 Resources --- .../resource_openstack_images_image_v2.go | 6 +- ...resource_openstack_images_image_v2_test.go | 30 +++++++++ .../resource_openstack_lb_loadbalancer_v2.go | 9 ++- ...ource_openstack_lb_loadbalancer_v2_test.go | 43 ++++++++++++ .../resource_openstack_lb_member_v2.go | 9 ++- .../resource_openstack_lb_member_v2_test.go | 63 ++++++++++++++++++ .../resource_openstack_lb_monitor_v2.go | 9 ++- .../resource_openstack_lb_monitor_v2_test.go | 65 +++++++++++++++++++ .../resource_openstack_lb_pool_v2.go | 9 ++- .../resource_openstack_lb_pool_v2_test.go | 56 ++++++++++++++++ 10 files changed, 290 insertions(+), 9 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_images_image_v2.go b/builtin/providers/openstack/resource_openstack_images_image_v2.go index 5b61e54bbc2f..483494334a5c 100644 --- a/builtin/providers/openstack/resource_openstack_images_image_v2.go +++ b/builtin/providers/openstack/resource_openstack_images_image_v2.go @@ -29,6 +29,10 @@ func resourceImagesImageV2() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "checksum": &schema.Schema{ Type: schema.TypeString, @@ -226,7 +230,7 @@ func resourceImagesImageV2Create(d *schema.ResourceData, meta interface{}) error Pending: []string{string(images.ImageStatusQueued), string(images.ImageStatusSaving)}, Target: []string{string(images.ImageStatusActive)}, Refresh: resourceImagesImageV2RefreshFunc(imageClient, d.Id(), fileSize, fileChecksum), - Timeout: 30 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 10 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_images_image_v2_test.go b/builtin/providers/openstack/resource_openstack_images_image_v2_test.go index cbaf716ba9f7..b1201040eedc 100644 --- a/builtin/providers/openstack/resource_openstack_images_image_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_images_image_v2_test.go @@ -135,6 +135,24 @@ func TestAccImagesImageV2_visibility(t *testing.T) { }) } +func TestAccImagesImageV2_timeout(t *testing.T) { + var image images.Image + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccImagesImageV2_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckImagesImageV2Exists("openstack_images_image_v2.image_1", &image), + ), + }, + }, + }) +} + func testAccCheckImagesImageV2Destroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) imageClient, err := config.imageV2Client(OS_REGION_NAME) @@ -326,3 +344,15 @@ var testAccImagesImageV2_visibility_2 = ` disk_format = "qcow2" visibility = "public" }` + +var testAccImagesImageV2_timeout = ` + resource "openstack_images_image_v2" "image_1" { + name = "Rancher TerraformAccTest" + image_source_url = "https://releases.rancher.com/os/latest/rancheros-openstack.img" + container_format = "bare" + disk_format = "qcow2" + + timeouts { + create = "10m" + } + }` diff --git a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go index a4489e52a91c..c4e17995fd2a 100644 --- a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2.go @@ -20,6 +20,11 @@ func resourceLoadBalancerV2() *schema.Resource { Update: resourceLoadBalancerV2Update, Delete: resourceLoadBalancerV2Delete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -138,7 +143,7 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForLoadBalancerActive(networkingClient, lb.ID), - Timeout: 20 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -245,7 +250,7 @@ func resourceLoadBalancerV2Delete(d *schema.ResourceData, meta interface{}) erro Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForLoadBalancerDelete(networkingClient, d.Id()), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2_test.go b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2_test.go index 66689431410c..0b157b16ad18 100644 --- a/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_loadbalancer_v2_test.go @@ -97,6 +97,24 @@ func TestAccLBV2LoadBalancer_secGroup(t *testing.T) { }) } +func TestAccLBV2LoadBalancer_timeout(t *testing.T) { + var lb loadbalancers.LoadBalancer + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccLBV2LoadBalancerConfig_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV2LoadBalancerExists("openstack_lb_loadbalancer_v2.loadbalancer_1", &lb), + ), + }, + }, + }) +} + func testAccCheckLBV2LoadBalancerDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -310,3 +328,28 @@ resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { depends_on = ["openstack_networking_secgroup_v2.secgroup_1"] } ` + +const testAccLBV2LoadBalancerConfig_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { + name = "loadbalancer_1" + loadbalancer_provider = "haproxy" + vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_member_v2.go b/builtin/providers/openstack/resource_openstack_lb_member_v2.go index 0d627f8cb7c2..61326bac3f2c 100644 --- a/builtin/providers/openstack/resource_openstack_lb_member_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_member_v2.go @@ -19,6 +19,11 @@ func resourceMemberV2() *schema.Resource { Update: resourceMemberV2Update, Delete: resourceMemberV2Delete, + 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, @@ -152,7 +157,7 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForMemberActive(networkingClient, poolID, member.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -233,7 +238,7 @@ func resourceMemberV2Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForMemberDelete(networkingClient, d.Get("pool_id").(string), d.Id()), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_lb_member_v2_test.go b/builtin/providers/openstack/resource_openstack_lb_member_v2_test.go index b75d401c9d1f..488b9fefc948 100644 --- a/builtin/providers/openstack/resource_openstack_lb_member_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_member_v2_test.go @@ -33,6 +33,24 @@ func TestAccLBV2Member_basic(t *testing.T) { }) } +func TestAccLBV2Member_timeout(t *testing.T) { + var member pools.Member + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV2MemberDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: TestAccLBV2MemberConfig_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV2MemberExists("openstack_lb_member_v2.member_1", &member), + ), + }, + }, + }) +} + func testAccCheckLBV2MemberDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -169,3 +187,48 @@ resource "openstack_lb_member_v2" "member_1" { subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" } ` + +const TestAccLBV2MemberConfig_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + network_id = "${openstack_networking_network_v2.network_1.id}" + cidr = "192.168.199.0/24" + ip_version = 4 +} + +resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { + name = "loadbalancer_1" + vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_lb_listener_v2" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}" +} + +resource "openstack_lb_pool_v2" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = "${openstack_lb_listener_v2.listener_1.id}" +} + +resource "openstack_lb_member_v2" "member_1" { + address = "192.168.199.10" + protocol_port = 8080 + pool_id = "${openstack_lb_pool_v2.pool_1.id}" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go index 736417c2d7e6..061c270e57f8 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v2.go @@ -19,6 +19,11 @@ func resourceMonitorV2() *schema.Resource { Update: resourceMonitorV2Update, Delete: resourceMonitorV2Delete, + 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, @@ -127,7 +132,7 @@ func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForMonitorActive(networkingClient, monitor.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -226,7 +231,7 @@ func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForMonitorDelete(networkingClient, d.Id()), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_lb_monitor_v2_test.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v2_test.go index f293b4d6787f..a7f095301eba 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v2_test.go @@ -36,6 +36,24 @@ func TestAccLBV2Monitor_basic(t *testing.T) { }) } +func TestAccLBV2Monitor_timeout(t *testing.T) { + var monitor monitors.Monitor + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV2MonitorDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: TestAccLBV2MonitorConfig_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV2MonitorExists(t, "openstack_lb_monitor_v2.monitor_1", &monitor), + ), + }, + }, + }) +} + func testAccCheckLBV2MonitorDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -173,3 +191,50 @@ resource "openstack_lb_monitor_v2" "monitor_1" { pool_id = "${openstack_lb_pool_v2.pool_1.id}" } ` + +const TestAccLBV2MonitorConfig_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { + name = "loadbalancer_1" + vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_lb_listener_v2" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}" +} + +resource "openstack_lb_pool_v2" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = "${openstack_lb_listener_v2.listener_1.id}" +} + +resource "openstack_lb_monitor_v2" "monitor_1" { + name = "monitor_1" + type = "PING" + delay = 20 + timeout = 10 + max_retries = 5 + pool_id = "${openstack_lb_pool_v2.pool_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v2.go b/builtin/providers/openstack/resource_openstack_lb_pool_v2.go index a9dc8dea4727..73742c668619 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v2.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v2.go @@ -19,6 +19,11 @@ func resourcePoolV2() *schema.Resource { Update: resourcePoolV2Update, Delete: resourcePoolV2Delete, + 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, @@ -174,7 +179,7 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForPoolActive(networkingClient, pool.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -258,7 +263,7 @@ func resourcePoolV2Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForPoolDelete(networkingClient, d.Id()), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutDelete), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v2_test.go b/builtin/providers/openstack/resource_openstack_lb_pool_v2_test.go index 286dda2a6442..6af15374a1e7 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v2_test.go @@ -33,6 +33,24 @@ func TestAccLBV2Pool_basic(t *testing.T) { }) } +func TestAccLBV2Pool_timeout(t *testing.T) { + var pool pools.Pool + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV2PoolDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: TestAccLBV2PoolConfig_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV2PoolExists("openstack_lb_pool_v2.pool_1", &pool), + ), + }, + }, + }) +} + func testAccCheckLBV2PoolDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -152,3 +170,41 @@ resource "openstack_lb_pool_v2" "pool_1" { listener_id = "${openstack_lb_listener_v2.listener_1.id}" } ` + +const TestAccLBV2PoolConfig_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { + name = "loadbalancer_1" + vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_lb_listener_v2" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}" +} + +resource "openstack_lb_pool_v2" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = "${openstack_lb_listener_v2.listener_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +`