Skip to content

Commit

Permalink
Merge pull request #2285 from cvvs/b_provider_openstack_router_adminbool
Browse files Browse the repository at this point in the history
provider/openstack: change router resource admin_state_up from string to bool
  • Loading branch information
mitchellh committed Jun 25, 2015
2 parents c223518 + eabaf8a commit 3815122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ func resourceComputeInstanceV2() *schema.Resource {
},
},
"security_groups": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString},
Set: func(v interface{}) int {
return hashcode.String(v.(string))
},
},
"availability_zone": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -547,7 +550,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e

if d.HasChange("security_groups") {
oldSGRaw, newSGRaw := d.GetChange("security_groups")
oldSGSlice, newSGSlice := oldSGRaw.([]interface{}), newSGRaw.([]interface{})
oldSGSlice, newSGSlice := oldSGRaw.(*schema.Set).List(), newSGRaw.(*schema.Set).List()
oldSGSet := schema.NewSet(func(v interface{}) int { return hashcode.String(v.(string)) }, oldSGSlice)
newSGSet := schema.NewSet(func(v interface{}) int { return hashcode.String(v.(string)) }, newSGSlice)
secgroupsToAdd := newSGSet.Difference(oldSGSet)
Expand Down Expand Up @@ -754,7 +757,7 @@ func ServerV2StateRefreshFunc(client *gophercloud.ServiceClient, instanceID stri
}

func resourceInstanceSecGroupsV2(d *schema.ResourceData) []string {
rawSecGroups := d.Get("security_groups").([]interface{})
rawSecGroups := d.Get("security_groups").(*schema.Set).List()
secgroups := make([]string, len(rawSecGroups))
for i, raw := range rawSecGroups {
secgroups[i] = raw.(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package openstack
import (
"fmt"
"log"
"strconv"

"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud"
Expand All @@ -30,7 +29,7 @@ func resourceNetworkingRouterV2() *schema.Resource {
ForceNew: false,
},
"admin_state_up": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
},
Expand Down Expand Up @@ -61,12 +60,8 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
TenantID: d.Get("tenant_id").(string),
}

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'")
}
if asuRaw, ok := d.GetOk("admin_state_up"); ok {
asu := asuRaw.(bool)
createOpts.AdminStateUp = &asu
}

Expand Down Expand Up @@ -114,7 +109,7 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Retreived Router %s: %+v", d.Id(), n)

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("external_gateway", n.GatewayInfo.NetworkID)

Expand All @@ -133,14 +128,8 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
updateOpts.Name = d.Get("name").(string)
}
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'")
}
updateOpts.AdminStateUp = &asu
}
asu := d.Get("admin_state_up").(bool)
updateOpts.AdminStateUp = &asu
}

log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts)
Expand Down

0 comments on commit 3815122

Please sign in to comment.