provider/openstack: openstack router admin state

Change openstack router resource admin state from a string to a
boolean.

Same technique as mitchellh's fix in
https://github.com/hashicorp/terraform/pull/1745
This commit is contained in:
cvvs 2015-06-09 10:25:54 -06:00
parent 646fd76e07
commit eabaf8a088
1 changed files with 6 additions and 17 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"
@ -30,7 +29,7 @@ func resourceNetworkingRouterV2() *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,
ForceNew: false, ForceNew: false,
}, },
@ -61,12 +60,8 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
TenantID: d.Get("tenant_id").(string), TenantID: d.Get("tenant_id").(string),
} }
asuRaw := d.Get("admin_state_up").(string) if asuRaw, ok := d.GetOk("admin_state_up"); ok {
if asuRaw != "" { asu := asuRaw.(bool)
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 createOpts.AdminStateUp = &asu
} }
@ -114,7 +109,7 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Retreived Router %s: %+v", d.Id(), n) log.Printf("[DEBUG] Retreived Router %s: %+v", d.Id(), n)
d.Set("name", n.Name) d.Set("name", n.Name)
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp)) d.Set("admin_state_up", n.AdminStateUp)
d.Set("tenant_id", n.TenantID) d.Set("tenant_id", n.TenantID)
d.Set("external_gateway", n.GatewayInfo.NetworkID) d.Set("external_gateway", n.GatewayInfo.NetworkID)
@ -133,14 +128,8 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
updateOpts.Name = d.Get("name").(string) updateOpts.Name = d.Get("name").(string)
} }
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 Router %s with options: %+v", d.Id(), updateOpts) log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts)