Skip to content

Commit

Permalink
LBaaS V2: Add OpenContrail monitor workaround (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored and ozerovandrei committed Aug 17, 2019
1 parent 5d88729 commit c6e233e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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
```

0 comments on commit c6e233e

Please sign in to comment.