Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/openstack: Adding Timeouts to LBaaS v1 Resources #12867

Merged
merged 1 commit into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -100,11 +117,25 @@ 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
max_retries = 3
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"
}
}
`
9 changes: 7 additions & 2 deletions builtin/providers/openstack/resource_openstack_lb_pool_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
45 changes: 45 additions & 0 deletions builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`
9 changes: 7 additions & 2 deletions builtin/providers/openstack/resource_openstack_lb_vip_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
56 changes: 56 additions & 0 deletions builtin/providers/openstack/resource_openstack_lb_vip_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
`