provider/openstack: gophercloud migration: Making GatewayIP computed

This commit is contained in:
Joe Topjian 2016-10-11 04:49:28 +00:00
parent 520b3dda82
commit ed0fe74d59
1 changed files with 19 additions and 11 deletions

View File

@ -71,12 +71,12 @@ func resourceNetworkingSubnetV2() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: false, ForceNew: false,
Computed: true,
}, },
"no_gateway": &schema.Schema{ "no_gateway": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
ForceNew: false, ForceNew: false,
Deprecated: "This argument is no longer required. Instead, omit gateway_ip or set it to an empty string",
}, },
"ip_version": &schema.Schema{ "ip_version": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
@ -144,13 +144,14 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
MapValueSpecs(d), MapValueSpecs(d),
} }
if v, ok := d.GetOk("gateway_ip"); ok {
noGateway := d.Get("no_gateway").(bool) noGateway := d.Get("no_gateway").(bool)
if noGateway { gatewayIP := d.Get("gateway_ip").(string)
return fmt.Errorf("Both gateway_ip and no_gateway cannot be set.")
if gatewayIP != "" && noGateway {
return fmt.Errorf("Both gateway_ip and no_gateway cannot be set")
} }
gatewayIP := v.(string) if gatewayIP != "" {
createOpts.GatewayIP = &gatewayIP createOpts.GatewayIP = &gatewayIP
} }
@ -198,7 +199,7 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
return CheckDeleted(d, err, "subnet") return CheckDeleted(d, err, "subnet")
} }
log.Printf("[DEBUG] Retrieved Subnet %s: %+v", d.Id(), s) log.Printf("[DEBUG] Retrieved Subnet %s: %#v", d.Id(), s)
d.Set("network_id", s.NetworkID) d.Set("network_id", s.NetworkID)
d.Set("cidr", s.CIDR) d.Set("cidr", s.CIDR)
@ -232,6 +233,13 @@ func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{})
var updateOpts subnets.UpdateOpts var updateOpts subnets.UpdateOpts
noGateway := d.Get("no_gateway").(bool)
gatewayIP := d.Get("gateway_ip").(string)
if gatewayIP != "" && noGateway {
return fmt.Errorf("Both gateway_ip and no_gateway cannot be set")
}
if d.HasChange("name") { if d.HasChange("name") {
updateOpts.Name = d.Get("name").(string) updateOpts.Name = d.Get("name").(string)
} }