2018-06-14 20:22:02 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file is automatically generated by Magic Modules and manual
|
|
|
|
// changes will be clobbered when the file is regenerated.
|
|
|
|
//
|
|
|
|
// Please read more about how to change this file in
|
|
|
|
// .github/CONTRIBUTING.md.
|
|
|
|
//
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-08-26 05:39:29 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2018-06-19 20:56:06 +00:00
|
|
|
"reflect"
|
2018-06-14 20:22:02 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
2014-08-26 05:39:29 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2018-06-14 20:22:02 +00:00
|
|
|
compute "google.golang.org/api/compute/v1"
|
2014-08-26 05:39:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func resourceComputeRoute() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceComputeRouteCreate,
|
|
|
|
Read: resourceComputeRouteRead,
|
|
|
|
Delete: resourceComputeRouteDelete,
|
2018-06-14 20:22:02 +00:00
|
|
|
|
2017-04-28 04:44:37 +00:00
|
|
|
Importer: &schema.ResourceImporter{
|
2018-06-14 20:22:02 +00:00
|
|
|
State: resourceComputeRouteImport,
|
|
|
|
},
|
|
|
|
|
|
|
|
Timeouts: &schema.ResourceTimeout{
|
|
|
|
Create: schema.DefaultTimeout(240 * time.Second),
|
|
|
|
Delete: schema.DefaultTimeout(240 * time.Second),
|
2017-04-28 04:44:37 +00:00
|
|
|
},
|
2014-08-26 05:39:29 +00:00
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
2018-06-14 20:22:02 +00:00
|
|
|
"dest_range": {
|
2014-08-26 05:39:29 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"name": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
ValidateFunc: validateRegexp(`^[a-z]([-a-z0-9]*[a-z0-9])?$`),
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"network": {
|
2017-10-13 18:05:22 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"description": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
"priority": {
|
2016-04-10 21:34:15 +00:00
|
|
|
Type: schema.TypeInt,
|
2018-01-27 21:37:32 +00:00
|
|
|
Optional: true,
|
2016-04-10 21:34:15 +00:00
|
|
|
ForceNew: true,
|
2018-01-27 21:37:32 +00:00
|
|
|
Default: 1000,
|
2016-04-10 21:34:15 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"tags": {
|
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
},
|
|
|
|
Set: schema.HashString,
|
|
|
|
},
|
|
|
|
"next_hop_gateway": {
|
2017-10-13 18:05:22 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"next_hop_instance": {
|
2017-11-10 18:57:53 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
DiffSuppressFunc: compareSelfLinkOrResourceName,
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"next_hop_ip": {
|
2014-08-26 05:39:29 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"next_hop_vpn_tunnel": {
|
2015-09-04 20:54:18 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"next_hop_network": {
|
2016-04-10 21:34:15 +00:00
|
|
|
Type: schema.TypeString,
|
2017-11-28 00:32:20 +00:00
|
|
|
Computed: true,
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"next_hop_instance_zone": &schema.Schema{
|
2018-02-15 21:03:28 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"project": {
|
2017-10-13 18:05:22 +00:00
|
|
|
Type: schema.TypeString,
|
2018-06-14 20:22:02 +00:00
|
|
|
Optional: true,
|
2017-10-13 18:05:22 +00:00
|
|
|
Computed: true,
|
2018-06-14 20:22:02 +00:00
|
|
|
ForceNew: true,
|
2017-10-13 18:05:22 +00:00
|
|
|
},
|
2018-06-14 20:22:02 +00:00
|
|
|
"self_link": {
|
2017-10-13 18:05:22 +00:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2014-08-26 05:39:29 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeRouteCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-19 20:56:06 +00:00
|
|
|
obj := make(map[string]interface{})
|
2018-06-14 20:22:02 +00:00
|
|
|
destRangeProp, err := expandComputeRouteDestRange(d.Get("dest_range"), d, config)
|
2014-08-26 05:39:29 +00:00
|
|
|
if err != nil {
|
2017-10-13 18:05:22 +00:00
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("dest_range"); !isEmptyValue(reflect.ValueOf(destRangeProp)) && (ok || !reflect.DeepEqual(v, destRangeProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["destRange"] = destRangeProp
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
2018-06-14 20:22:02 +00:00
|
|
|
descriptionProp, err := expandComputeRouteDescription(d.Get("description"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["description"] = descriptionProp
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
2018-06-14 20:22:02 +00:00
|
|
|
nameProp, err := expandComputeRouteName(d.Get("name"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["name"] = nameProp
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
2018-06-14 20:22:02 +00:00
|
|
|
networkProp, err := expandComputeRouteNetwork(d.Get("network"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("network"); !isEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["network"] = networkProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
priorityProp, err := expandComputeRoutePriority(d.Get("priority"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("priority"); !isEmptyValue(reflect.ValueOf(priorityProp)) && (ok || !reflect.DeepEqual(v, priorityProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["priority"] = priorityProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
tagsProp, err := expandComputeRouteTags(d.Get("tags"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("tags"); !isEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["tags"] = tagsProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
nextHopGatewayProp, err := expandComputeRouteNextHopGateway(d.Get("next_hop_gateway"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("next_hop_gateway"); !isEmptyValue(reflect.ValueOf(nextHopGatewayProp)) && (ok || !reflect.DeepEqual(v, nextHopGatewayProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["nextHopGateway"] = nextHopGatewayProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
nextHopInstanceProp, err := expandComputeRouteNextHopInstance(d.Get("next_hop_instance"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("next_hop_instance"); !isEmptyValue(reflect.ValueOf(nextHopInstanceProp)) && (ok || !reflect.DeepEqual(v, nextHopInstanceProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["nextHopInstance"] = nextHopInstanceProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
nextHopIpProp, err := expandComputeRouteNextHopIp(d.Get("next_hop_ip"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("next_hop_ip"); !isEmptyValue(reflect.ValueOf(nextHopIpProp)) && (ok || !reflect.DeepEqual(v, nextHopIpProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["nextHopIp"] = nextHopIpProp
|
2018-06-14 20:22:02 +00:00
|
|
|
}
|
|
|
|
nextHopVpnTunnelProp, err := expandComputeRouteNextHopVpnTunnel(d.Get("next_hop_vpn_tunnel"), d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-06-22 00:46:50 +00:00
|
|
|
} else if v, ok := d.GetOkExists("next_hop_vpn_tunnel"); !isEmptyValue(reflect.ValueOf(nextHopVpnTunnelProp)) && (ok || !reflect.DeepEqual(v, nextHopVpnTunnelProp)) {
|
2018-06-19 20:56:06 +00:00
|
|
|
obj["nextHopVpnTunnel"] = nextHopVpnTunnelProp
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/routes")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
log.Printf("[DEBUG] Creating new Route: %#v", obj)
|
|
|
|
res, err := Post(config, url, obj)
|
2014-08-26 05:39:29 +00:00
|
|
|
if err != nil {
|
2018-06-14 20:22:02 +00:00
|
|
|
return fmt.Errorf("Error creating Route: %s", err)
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
// Store the ID now
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error constructing id: %s", err)
|
|
|
|
}
|
|
|
|
d.SetId(id)
|
2014-08-26 05:39:29 +00:00
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
2014-08-26 05:39:29 +00:00
|
|
|
if err != nil {
|
2015-09-24 20:30:12 +00:00
|
|
|
return err
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
waitErr := computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Creating Route",
|
|
|
|
int(d.Timeout(schema.TimeoutCreate).Minutes()))
|
|
|
|
|
|
|
|
if waitErr != nil {
|
|
|
|
// The resource didn't actually create
|
|
|
|
d.SetId("")
|
|
|
|
return fmt.Errorf("Error waiting to create Route: %s", waitErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[DEBUG] Finished creating Route %q: %#v", d.Id(), res)
|
|
|
|
|
2014-08-26 05:39:29 +00:00
|
|
|
return resourceComputeRouteRead(d, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/routes/{{name}}")
|
2014-08-26 05:39:29 +00:00
|
|
|
if err != nil {
|
2018-06-14 20:22:02 +00:00
|
|
|
return err
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
res, err := Get(config, url)
|
2017-10-13 18:05:22 +00:00
|
|
|
if err != nil {
|
2018-06-14 20:22:02 +00:00
|
|
|
return handleNotFoundError(err, d, fmt.Sprintf("ComputeRoute %q", d.Id()))
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = resourceComputeRouteDecoder(d, meta, res)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := d.Set("dest_range", flattenComputeRouteDestRange(res["destRange"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("description", flattenComputeRouteDescription(res["description"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("name", flattenComputeRouteName(res["name"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("network", flattenComputeRouteNetwork(res["network"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("priority", flattenComputeRoutePriority(res["priority"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("tags", flattenComputeRouteTags(res["tags"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("next_hop_gateway", flattenComputeRouteNextHopGateway(res["nextHopGateway"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("next_hop_instance", flattenComputeRouteNextHopInstance(res["nextHopInstance"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("next_hop_ip", flattenComputeRouteNextHopIp(res["nextHopIp"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("next_hop_vpn_tunnel", flattenComputeRouteNextHopVpnTunnel(res["nextHopVpnTunnel"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("next_hop_network", flattenComputeRouteNextHopNetwork(res["nextHopNetwork"])); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
|
|
|
if err := d.Set("project", project); err != nil {
|
|
|
|
return fmt.Errorf("Error reading Route: %s", err)
|
|
|
|
}
|
2015-02-10 11:15:07 +00:00
|
|
|
|
2014-08-26 05:39:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeRouteDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
config := meta.(*Config)
|
|
|
|
|
2016-04-10 16:59:57 +00:00
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/routes/{{name}}")
|
2014-08-26 05:39:29 +00:00
|
|
|
if err != nil {
|
2018-06-14 20:22:02 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("[DEBUG] Deleting Route %q", d.Id())
|
|
|
|
res, err := Delete(config, url)
|
|
|
|
if err != nil {
|
|
|
|
return handleNotFoundError(err, d, "Route")
|
|
|
|
}
|
|
|
|
|
|
|
|
op := &compute.Operation{}
|
|
|
|
err = Convert(res, op)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-08-26 05:39:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
err = computeOperationWaitTime(
|
|
|
|
config.clientCompute, op, project, "Deleting Route",
|
|
|
|
int(d.Timeout(schema.TimeoutDelete).Minutes()))
|
|
|
|
|
2014-08-26 05:44:27 +00:00
|
|
|
if err != nil {
|
2015-09-24 20:30:12 +00:00
|
|
|
return err
|
2014-08-26 05:44:27 +00:00
|
|
|
}
|
2014-08-26 05:39:29 +00:00
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
log.Printf("[DEBUG] Finished deleting Route %q: %#v", d.Id(), res)
|
2014-08-26 05:39:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-10-13 18:05:22 +00:00
|
|
|
|
2018-06-14 20:22:02 +00:00
|
|
|
func resourceComputeRouteImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
|
|
|
config := meta.(*Config)
|
|
|
|
parseImportId([]string{"projects/(?P<project>[^/]+)/global/routes/(?P<name>[^/]+)", "(?P<project>[^/]+)/(?P<name>[^/]+)", "(?P<name>[^/]+)"}, d, config)
|
|
|
|
|
|
|
|
// Replace import id for the resource id
|
|
|
|
id, err := replaceVars(d, config, "{{name}}")
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error constructing id: %s", err)
|
|
|
|
}
|
|
|
|
d.SetId(id)
|
|
|
|
|
|
|
|
return []*schema.ResourceData{d}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteDestRange(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteDescription(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteName(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNetwork(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRoutePriority(v interface{}) interface{} {
|
|
|
|
// Handles the string fixed64 format
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
|
|
|
|
return intVal
|
|
|
|
} // let terraform core handle it if we can't convert the string to an int.
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteTags(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNextHopGateway(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNextHopInstance(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNextHopIp(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNextHopVpnTunnel(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func flattenComputeRouteNextHopNetwork(v interface{}) interface{} {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteDestRange(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteNetwork(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
f, err := parseGlobalFieldValue("networks", v.(string), "project", d, config, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Invalid value for network: %s", err)
|
|
|
|
}
|
|
|
|
return f.RelativeLink(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRoutePriority(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteTags(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v.(*schema.Set).List(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteNextHopGateway(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
if v == "default-internet-gateway" {
|
|
|
|
project, err := getProject(d, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("projects/%s/global/gateways/default-internet-gateway", project), nil
|
|
|
|
} else {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteNextHopInstance(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
if v == "" {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
val, err := parseZonalFieldValue("instances", v.(string), "project", "next_hop_instance_zone", d, config, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nextInstance, err := config.clientCompute.Instances.Get(val.Project, val.Zone, val.Name).Do()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nextInstance.SelfLink, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteNextHopIp(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func expandComputeRouteNextHopVpnTunnel(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceComputeRouteDecoder(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) {
|
|
|
|
if v, ok := res["nextHopInstance"]; ok {
|
|
|
|
val, err := parseZonalFieldValue("instances", v.(string), "project", "next_hop_instance_zone", d, meta.(*Config), true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
d.Set("next_hop_instance_zone", val.Zone)
|
|
|
|
res["nextHopInstance"] = val.RelativeLink()
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2017-10-13 18:05:22 +00:00
|
|
|
}
|