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

LBaaS V2: Add OpenContrail monitor workaround #840

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
24 changes: 21 additions & 3 deletions openstack/resource_openstack_lb_monitor_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openstack
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -19,7 +20,7 @@ func resourceMonitorV2() *schema.Resource {
Update: resourceMonitorV2Update,
Delete: resourceMonitorV2Delete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
State: resourceMonitorV2Import,
},

Timeouts: &schema.ResourceTimeout{
Expand Down Expand Up @@ -178,8 +179,8 @@ func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Retrieved monitor %s: %#v", d.Id(), monitor)

// Required by import
if len(monitor.Pools) > 0 {
// OpenContrail workaround (https://github.com/terraform-providers/terraform-provider-openstack/issues/762)
if len(monitor.Pools) > 0 && monitor.Pools[0].ID != "" {
d.Set("pool_id", monitor.Pools[0].ID)
}

Expand Down Expand Up @@ -329,3 +330,20 @@ func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error {

return nil
}

func resourceMonitorV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.SplitN(d.Id(), "/", 2)
monitorID := parts[0]

if len(monitorID) == 0 {
return nil, fmt.Errorf("Invalid format specified for openstack_lb_monitor_v2. Format must be <monitorID>[/<poolID>]")
}

d.SetId(monitorID)

if len(parts) == 2 {
d.Set("pool_id", parts[1])
}

return []*schema.ResourceData{d}, nil
}
6 changes: 6 additions & 0 deletions website/docs/r/lb_monitor_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ Load Balancer Pool Monitor can be imported using the Monitor ID, e.g.:
```
$ terraform import openstack_lb_monitor_v2.monitor_1 47c26fc3-2403-427a-8c79-1589bd0533c2
```

In case of using OpenContrail, the import may not work properly. If you face an issue, try to import the monitor providing its parent pool ID:

```
$ terraform import openstack_lb_monitor_v2.monitor_1 47c26fc3-2403-427a-8c79-1589bd0533c2/708bc224-0f8c-4981-ac82-97095fe051b6
```