Skip to content

Commit

Permalink
Merge pull request #1745 from hashicorp/b-openstack-bool
Browse files Browse the repository at this point in the history
provider/openstack: enable_dhcp should be bool [GH-1741]
  • Loading branch information
mitchellh committed Apr 30, 2015
2 parents f843370 + 914740f commit aaf94e7
Showing 1 changed file with 7 additions and 18 deletions.
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/hashcode"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -72,7 +71,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
ForceNew: true,
},
"enable_dhcp": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
},
Expand Down Expand Up @@ -125,13 +124,9 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
HostRoutes: resourceSubnetHostRoutesV2(d),
}

edRaw := d.Get("enable_dhcp").(string)
if edRaw != "" {
ed, err := strconv.ParseBool(edRaw)
if err != nil {
return fmt.Errorf("enable_dhcp, if provided, must be either 'true' or 'false'")
}
createOpts.EnableDHCP = &ed
if raw, ok := d.GetOk("enable_dhcp"); ok {
value := raw.(bool)
createOpts.EnableDHCP = &value
}

log.Printf("[DEBUG] Create Options: %#v", createOpts)
Expand Down Expand Up @@ -167,7 +162,7 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP)
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
d.Set("enable_dhcp", s.EnableDHCP)
d.Set("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes)

Expand Down Expand Up @@ -200,14 +195,8 @@ func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{})
}

if d.HasChange("enable_dhcp") {
edRaw := d.Get("enable_dhcp").(string)
if edRaw != "" {
ed, err := strconv.ParseBool(edRaw)
if err != nil {
return fmt.Errorf("enable_dhcp, if provided, must be either 'true' or 'false'")
}
updateOpts.EnableDHCP = &ed
}
v := d.Get("enable_dhcp").(bool)
updateOpts.EnableDHCP = &v
}

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

0 comments on commit aaf94e7

Please sign in to comment.