From fbf1732a7b1e8acda25bebd51c2f50dfa28d2c51 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sun, 19 Mar 2017 11:18:03 -0600 Subject: [PATCH] provider/openstack: Adding Timeouts to LBaaS v1 Resources (#12867) --- .../resource_openstack_lb_member_v1.go | 9 ++- .../resource_openstack_lb_member_v1_test.go | 50 +++++++++++++++++ .../resource_openstack_lb_monitor_v1.go | 9 ++- .../resource_openstack_lb_monitor_v1_test.go | 35 +++++++++++- .../resource_openstack_lb_pool_v1.go | 9 ++- .../resource_openstack_lb_pool_v1_test.go | 45 +++++++++++++++ .../openstack/resource_openstack_lb_vip_v1.go | 9 ++- .../resource_openstack_lb_vip_v1_test.go | 56 +++++++++++++++++++ 8 files changed, 212 insertions(+), 10 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_lb_member_v1.go b/builtin/providers/openstack/resource_openstack_lb_member_v1.go index 44300b8dc..e6dc3da9f 100644 --- a/builtin/providers/openstack/resource_openstack_lb_member_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_member_v1.go @@ -22,6 +22,11 @@ func resourceLBMemberV1() *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, @@ -91,7 +96,7 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE", "INACTIVE", "CREATED", "DOWN"}, Refresh: waitForLBMemberActive(networkingClient, m.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -181,7 +186,7 @@ func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForLBMemberDelete(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_member_v1_test.go b/builtin/providers/openstack/resource_openstack_lb_member_v1_test.go index 099f50016..af840a5b5 100644 --- a/builtin/providers/openstack/resource_openstack_lb_member_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_member_v1_test.go @@ -33,6 +33,24 @@ func TestAccLBV1Member_basic(t *testing.T) { }) } +func TestAccLBV1Member_timeout(t *testing.T) { + var member members.Member + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV1MemberDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccLBV1Member_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV1MemberExists("openstack_lb_member_v1.member_1", &member), + ), + }, + }, + }) +} + func testAccCheckLBV1MemberDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -139,3 +157,35 @@ resource "openstack_lb_member_v1" "member_1" { pool_id = "${openstack_lb_pool_v1.pool_1.id}" } ` + +const testAccLBV1Member_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_pool_v1" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_lb_member_v1" "member_1" { + address = "192.168.199.10" + port = 80 + admin_state_up = true + pool_id = "${openstack_lb_pool_v1.pool_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go index 13c67cb96..26066cbea 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go @@ -23,6 +23,11 @@ func resourceLBMonitorV1() *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, @@ -125,7 +130,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForLBMonitorActive(networkingClient, m.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -216,7 +221,7 @@ func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForLBMonitorDelete(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_v1_test.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v1_test.go index 6b97ed44c..3da3b6623 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v1_test.go @@ -34,6 +34,24 @@ func TestAccLBV1Monitor_basic(t *testing.T) { }) } +func TestAccLBV1Monitor_timeout(t *testing.T) { + var monitor monitors.Monitor + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV1MonitorDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccLBV1Monitor_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV1MonitorExists("openstack_lb_monitor_v1.monitor_1", &monitor), + ), + }, + }, + }) +} + func testAccCheckLBV1MonitorDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -89,7 +107,6 @@ func testAccCheckLBV1MonitorExists(n string, monitor *monitors.Monitor) resource const testAccLBV1Monitor_basic = ` resource "openstack_lb_monitor_v1" "monitor_1" { - region = "%s" type = "PING" delay = 30 timeout = 5 @@ -100,7 +117,6 @@ resource "openstack_lb_monitor_v1" "monitor_1" { const testAccLBV1Monitor_update = ` resource "openstack_lb_monitor_v1" "monitor_1" { - region = "%s" type = "PING" delay = 20 timeout = 5 @@ -108,3 +124,18 @@ resource "openstack_lb_monitor_v1" "monitor_1" { admin_state_up = "true" } ` + +const testAccLBV1Monitor_timeout = ` +resource "openstack_lb_monitor_v1" "monitor_1" { + type = "PING" + delay = 30 + timeout = 5 + max_retries = 3 + admin_state_up = "true" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v1.go b/builtin/providers/openstack/resource_openstack_lb_pool_v1.go index a49acf74d..eb0436ddf 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v1.go @@ -26,6 +26,11 @@ func resourceLBPoolV1() *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, @@ -150,7 +155,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForLBPoolActive(networkingClient, p.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -331,7 +336,7 @@ func resourceLBPoolV1Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForLBPoolDelete(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_v1_test.go b/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go index 353d6df21..c21a74b0d 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go @@ -85,6 +85,25 @@ func TestAccLBV1Pool_fullstack(t *testing.T) { }) } +func TestAccLBV1Pool_timeout(t *testing.T) { + var pool pools.Pool + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccLBV1Pool_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV1PoolExists("openstack_lb_pool_v1.pool_1", &pool), + resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "lb_provider", "haproxy"), + ), + }, + }, + }) +} + func testAccCheckLBV1PoolDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -357,3 +376,29 @@ resource "openstack_lb_vip_v1" "vip_1" { pool_id = "${openstack_lb_pool_v1.pool_1.id}" } ` + +const testAccLBV1Pool_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_pool_v1" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + lb_provider = "haproxy" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + + timeouts { + create = "5m" + delete = "5m" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_lb_vip_v1.go b/builtin/providers/openstack/resource_openstack_lb_vip_v1.go index 39c935ff3..6e6d46d89 100644 --- a/builtin/providers/openstack/resource_openstack_lb_vip_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_vip_v1.go @@ -22,6 +22,11 @@ func resourceLBVipV1() *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 resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error { Pending: []string{"PENDING_CREATE"}, Target: []string{"ACTIVE"}, Refresh: waitForLBVIPActive(networkingClient, p.ID), - Timeout: 2 * time.Minute, + Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, } @@ -291,7 +296,7 @@ func resourceLBVipV1Delete(d *schema.ResourceData, meta interface{}) error { Pending: []string{"ACTIVE", "PENDING_DELETE"}, Target: []string{"DELETED"}, Refresh: waitForLBVIPDelete(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_vip_v1_test.go b/builtin/providers/openstack/resource_openstack_lb_vip_v1_test.go index 2d253c4ba..8fda99c83 100644 --- a/builtin/providers/openstack/resource_openstack_lb_vip_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_vip_v1_test.go @@ -34,6 +34,24 @@ func TestAccLBV1VIP_basic(t *testing.T) { }) } +func TestAccLBV1VIP_timeout(t *testing.T) { + var vip vips.VirtualIP + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLBV1VIPDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccLBV1VIP_timeout, + Check: resource.ComposeTestCheckFunc( + testAccCheckLBV1VIPExists("openstack_lb_vip_v1.vip_1", &vip), + ), + }, + }, + }) +} + func testAccCheckLBV1VIPDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) @@ -152,3 +170,41 @@ resource "openstack_lb_vip_v1" "vip_1" { } } ` + +const testAccLBV1VIP_timeout = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_lb_pool_v1" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_lb_vip_v1" "vip_1" { + name = "vip_1" + protocol = "HTTP" + port = 80 + admin_state_up = true + pool_id = "${openstack_lb_pool_v1.pool_1.id}" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + + persistence { + type = "SOURCE_IP" + } + + timeouts { + create = "5m" + delete = "5m" + } +} +`