provider/openstack: Clean up some attributes in LBaaS VIP resource

This commit makes a few attributes computed so the generated information
is accessible after creation.

It also fixes the "persistence" attribute, which previously had a typo.

Finally, it converts "admin_state_up" to a Boolean to match the majority
of other attributes of the same name.
This commit is contained in:
Joe Topjian 2015-11-14 20:19:06 +00:00
parent 7f95311491
commit b4242e6f35
2 changed files with 21 additions and 52 deletions

View File

@ -3,7 +3,6 @@ package openstack
import (
"fmt"
"log"
"strconv"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud"
@ -53,16 +52,19 @@ func resourceLBVipV1() *schema.Resource {
"tenant_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"address": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: false,
},
"persistence": &schema.Schema{
@ -73,6 +75,7 @@ func resourceLBVipV1() *schema.Resource {
"conn_limit": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: false,
},
"port_id": &schema.Schema{
@ -86,8 +89,9 @@ func resourceLBVipV1() *schema.Resource {
ForceNew: false,
},
"admin_state_up": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: false,
},
},
@ -114,14 +118,8 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
ConnLimit: gophercloud.MaybeInt(d.Get("conn_limit").(int)),
}
asuRaw := d.Get("admin_state_up").(string)
if asuRaw != "" {
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
asu := d.Get("admin_state_up").(bool)
createOpts.AdminStateUp = &asu
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
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("pool_id", p.PoolID)
d.Set("port_id", p.PortID)
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", p.TenantID)
} else {
d.Set("tenant_id", "")
}
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", "")
}
d.Set("admin_state_up", p.AdminStateUp)
return nil
}
@ -255,15 +224,9 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error {
}
}
if d.HasChange("admin_state_up") {
asuRaw := d.Get("admin_state_up").(string)
if asuRaw != "" {
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
asu := d.Get("admin_state_up").(bool)
updateOpts.AdminStateUp = &asu
}
}
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"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
persistence {
type = "SOURCE_IP"
}
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)
@ -148,5 +151,8 @@ var testAccLBV1VIP_update = fmt.Sprintf(`
protocol = "HTTP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
persistence {
type = "SOURCE_IP"
}
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)