Merge pull request #3927 from jtopjian/jtopjian-openstack-lbvip-attr-cleanup

provider/openstack: Clean up some attributes in LBaaS VIP resource
This commit is contained in:
Joe Topjian 2015-11-17 20:19:25 -07:00
commit 51a2fbd6ae
2 changed files with 21 additions and 52 deletions

View File

@ -3,7 +3,6 @@ package openstack
import ( import (
"fmt" "fmt"
"log" "log"
"strconv"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud"
@ -53,16 +52,19 @@ func resourceLBVipV1() *schema.Resource {
"tenant_id": &schema.Schema{ "tenant_id": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"address": &schema.Schema{ "address": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
"description": &schema.Schema{ "description": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true,
ForceNew: false, ForceNew: false,
}, },
"persistence": &schema.Schema{ "persistence": &schema.Schema{
@ -73,6 +75,7 @@ func resourceLBVipV1() *schema.Resource {
"conn_limit": &schema.Schema{ "conn_limit": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true,
ForceNew: false, ForceNew: false,
}, },
"port_id": &schema.Schema{ "port_id": &schema.Schema{
@ -86,8 +89,9 @@ func resourceLBVipV1() *schema.Resource {
ForceNew: false, ForceNew: false,
}, },
"admin_state_up": &schema.Schema{ "admin_state_up": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true,
ForceNew: false, ForceNew: false,
}, },
}, },
@ -114,14 +118,8 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
ConnLimit: gophercloud.MaybeInt(d.Get("conn_limit").(int)), ConnLimit: gophercloud.MaybeInt(d.Get("conn_limit").(int)),
} }
asuRaw := d.Get("admin_state_up").(string) asu := d.Get("admin_state_up").(bool)
if asuRaw != "" { createOpts.AdminStateUp = &asu
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
createOpts.AdminStateUp = &asu
}
log.Printf("[DEBUG] Create Options: %#v", createOpts) log.Printf("[DEBUG] Create Options: %#v", createOpts)
p, err := vips.Create(networkingClient, createOpts).Extract() p, err := vips.Create(networkingClient, createOpts).Extract()
@ -160,40 +158,11 @@ func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("port", p.ProtocolPort) d.Set("port", p.ProtocolPort)
d.Set("pool_id", p.PoolID) d.Set("pool_id", p.PoolID)
d.Set("port_id", p.PortID) d.Set("port_id", p.PortID)
d.Set("tenant_id", p.TenantID)
if t, exists := d.GetOk("tenant_id"); exists && t != "" { d.Set("address", p.Address)
d.Set("tenant_id", p.TenantID) d.Set("description", p.Description)
} else { d.Set("conn_limit", p.ConnLimit)
d.Set("tenant_id", "") d.Set("admin_state_up", p.AdminStateUp)
}
if t, exists := d.GetOk("address"); exists && t != "" {
d.Set("address", p.Address)
} else {
d.Set("address", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", p.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("persistence"); exists && t != "" {
d.Set("persistence", p.Description)
}
if t, exists := d.GetOk("conn_limit"); exists && t != "" {
d.Set("conn_limit", p.ConnLimit)
} else {
d.Set("conn_limit", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}
return nil return nil
} }
@ -255,14 +224,8 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
} }
} }
if d.HasChange("admin_state_up") { if d.HasChange("admin_state_up") {
asuRaw := d.Get("admin_state_up").(string) asu := d.Get("admin_state_up").(bool)
if asuRaw != "" { updateOpts.AdminStateUp = &asu
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
updateOpts.AdminStateUp = &asu
}
} }
log.Printf("[DEBUG] Updating OpenStack LB VIP %s with options: %+v", d.Id(), updateOpts) log.Printf("[DEBUG] Updating OpenStack LB VIP %s with options: %+v", d.Id(), updateOpts)

View File

@ -116,6 +116,9 @@ var testAccLBV1VIP_basic = fmt.Sprintf(`
protocol = "HTTP" protocol = "HTTP"
port = 80 port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
persistence {
type = "SOURCE_IP"
}
}`, }`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME) OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)
@ -148,5 +151,8 @@ var testAccLBV1VIP_update = fmt.Sprintf(`
protocol = "HTTP" protocol = "HTTP"
port = 80 port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
persistence {
type = "SOURCE_IP"
}
}`, }`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME) OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)