Merge pull request #1745 from hashicorp/b-openstack-bool

provider/openstack: enable_dhcp should be bool [GH-1741]
This commit is contained in:
Mitchell Hashimoto 2015-04-30 14:27:14 -07:00
commit aaf94e7cec
1 changed files with 7 additions and 18 deletions

View File

@ -3,7 +3,6 @@ package openstack
import ( import (
"fmt" "fmt"
"log" "log"
"strconv"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -72,7 +71,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
ForceNew: true, ForceNew: true,
}, },
"enable_dhcp": &schema.Schema{ "enable_dhcp": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeBool,
Optional: true, Optional: true,
ForceNew: false, ForceNew: false,
}, },
@ -125,13 +124,9 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
HostRoutes: resourceSubnetHostRoutesV2(d), HostRoutes: resourceSubnetHostRoutesV2(d),
} }
edRaw := d.Get("enable_dhcp").(string) if raw, ok := d.GetOk("enable_dhcp"); ok {
if edRaw != "" { value := raw.(bool)
ed, err := strconv.ParseBool(edRaw) createOpts.EnableDHCP = &value
if err != nil {
return fmt.Errorf("enable_dhcp, if provided, must be either 'true' or 'false'")
}
createOpts.EnableDHCP = &ed
} }
log.Printf("[DEBUG] Create Options: %#v", createOpts) log.Printf("[DEBUG] Create Options: %#v", createOpts)
@ -167,7 +162,7 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("tenant_id", s.TenantID) d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools) d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP) 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("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes) d.Set("host_routes", s.HostRoutes)
@ -200,14 +195,8 @@ func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{})
} }
if d.HasChange("enable_dhcp") { if d.HasChange("enable_dhcp") {
edRaw := d.Get("enable_dhcp").(string) v := d.Get("enable_dhcp").(bool)
if edRaw != "" { updateOpts.EnableDHCP = &v
ed, err := strconv.ParseBool(edRaw)
if err != nil {
return fmt.Errorf("enable_dhcp, if provided, must be either 'true' or 'false'")
}
updateOpts.EnableDHCP = &ed
}
} }
log.Printf("[DEBUG] Updating Subnet %s with options: %+v", d.Id(), updateOpts) log.Printf("[DEBUG] Updating Subnet %s with options: %+v", d.Id(), updateOpts)