From 60af6507037e138179e434108684d78c8292c745 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Thu, 12 Dec 2019 23:02:01 +0000 Subject: [PATCH] Moving nexthop ILB to GA Signed-off-by: Modular Magician --- google/resource_compute_route.go | 44 ++++++++++- .../resource_compute_route_generated_test.go | 75 +++++++++++++++++++ website/docs/r/compute_route.html.markdown | 22 +++--- 3 files changed, 127 insertions(+), 14 deletions(-) diff --git a/google/resource_compute_route.go b/google/resource_compute_route.go index 1dbf5153f90..257f85acc8e 100644 --- a/google/resource_compute_route.go +++ b/google/resource_compute_route.go @@ -86,7 +86,19 @@ partial valid URL: * 'projects/project/global/gateways/default-internet-gateway' * 'global/gateways/default-internet-gateway' * The string 'default-internet-gateway'.`, - ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel"}, + ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel", "next_hop_ilb"}, + }, + "next_hop_ilb": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + Description: `The URL to a forwarding rule of type loadBalancingScheme=INTERNAL that should handle matching packets. +You can only specify the forwarding rule as a partial or full URL. For example, the following are all valid URLs: +https://www.googleapis.com/compute/v1/projects/project/regions/region/forwardingRules/forwardingRule +regions/region/forwardingRules/forwardingRule +Note that this can only be used when the destinationRange is a public (non-RFC 1918) IP CIDR range.`, + ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel", "next_hop_ilb"}, }, "next_hop_instance": { Type: schema.TypeString, @@ -99,7 +111,7 @@ You can specify this as a full or partial URL. For example: * 'projects/project/zones/zone/instances/instance' * 'zones/zone/instances/instance' * Just the instance name, with the zone in 'next_hop_instance_zone'.`, - ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel"}, + ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel", "next_hop_ilb"}, }, "next_hop_ip": { Type: schema.TypeString, @@ -107,7 +119,7 @@ You can specify this as a full or partial URL. For example: Optional: true, ForceNew: true, Description: `Network IP address of an instance that should handle matching packets.`, - ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel"}, + ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel", "next_hop_ilb"}, }, "next_hop_vpn_tunnel": { Type: schema.TypeString, @@ -115,7 +127,7 @@ You can specify this as a full or partial URL. For example: ForceNew: true, DiffSuppressFunc: compareSelfLinkOrResourceName, Description: `URL to a VpnTunnel that should handle matching packets.`, - ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel"}, + ExactlyOneOf: []string{"next_hop_gateway", "next_hop_instance", "next_hop_ip", "next_hop_vpn_tunnel", "next_hop_ilb"}, }, "priority": { Type: schema.TypeInt, @@ -228,6 +240,12 @@ func resourceComputeRouteCreate(d *schema.ResourceData, meta interface{}) error } else if v, ok := d.GetOkExists("next_hop_vpn_tunnel"); !isEmptyValue(reflect.ValueOf(nextHopVpnTunnelProp)) && (ok || !reflect.DeepEqual(v, nextHopVpnTunnelProp)) { obj["nextHopVpnTunnel"] = nextHopVpnTunnelProp } + nextHopIlbProp, err := expandComputeRouteNextHopIlb(d.Get("next_hop_ilb"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("next_hop_ilb"); !isEmptyValue(reflect.ValueOf(nextHopIlbProp)) && (ok || !reflect.DeepEqual(v, nextHopIlbProp)) { + obj["nextHopIlb"] = nextHopIlbProp + } url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/routes") if err != nil { @@ -332,6 +350,9 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("next_hop_network", flattenComputeRouteNextHopNetwork(res["nextHopNetwork"], d)); err != nil { return fmt.Errorf("Error reading Route: %s", err) } + if err := d.Set("next_hop_ilb", flattenComputeRouteNextHopIlb(res["nextHopIlb"], d)); 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) } @@ -454,6 +475,13 @@ func flattenComputeRouteNextHopNetwork(v interface{}, d *schema.ResourceData) in return v } +func flattenComputeRouteNextHopIlb(v interface{}, d *schema.ResourceData) interface{} { + if v == nil { + return v + } + return ConvertSelfLinkToV1(v.(string)) +} + func expandComputeRouteDestRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } @@ -517,6 +545,14 @@ func expandComputeRouteNextHopVpnTunnel(v interface{}, d TerraformResourceData, return f.RelativeLink(), nil } +func expandComputeRouteNextHopIlb(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("forwardingRules", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for next_hop_ilb: %s", err) + } + return f.RelativeLink(), 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) diff --git a/google/resource_compute_route_generated_test.go b/google/resource_compute_route_generated_test.go index 96cbb9f081b..76df2f8268f 100644 --- a/google/resource_compute_route_generated_test.go +++ b/google/resource_compute_route_generated_test.go @@ -64,6 +64,81 @@ resource "google_compute_network" "default" { `, context) } +func TestAccComputeRoute_routeIlbExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouteDestroy, + Steps: []resource.TestStep{ + { + Config: testAccComputeRoute_routeIlbExample(context), + }, + { + ResourceName: "google_compute_route.route-ilb", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccComputeRoute_routeIlbExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_network" "default" { + name = "compute-network%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "compute-subnet%{random_suffix}" + ip_cidr_range = "10.0.1.0/24" + region = "us-central1" + network = google_compute_network.default.self_link +} + +resource "google_compute_health_check" "hc" { + name = "proxy-health-check%{random_suffix}" + check_interval_sec = 1 + timeout_sec = 1 + + tcp_health_check { + port = "80" + } +} + +resource "google_compute_region_backend_service" "backend" { + name = "compute-backend%{random_suffix}" + region = "us-central1" + health_checks = [google_compute_health_check.hc.self_link] +} + +resource "google_compute_forwarding_rule" "default" { + name = "compute-forwarding-rule%{random_suffix}" + region = "us-central1" + + load_balancing_scheme = "INTERNAL" + backend_service = google_compute_region_backend_service.backend.self_link + all_ports = true + network = google_compute_network.default.name + subnetwork = google_compute_subnetwork.default.name +} + +resource "google_compute_route" "route-ilb" { + name = "route-ilb%{random_suffix}" + dest_range = "0.0.0.0/0" + network = google_compute_network.default.name + next_hop_ilb = google_compute_forwarding_rule.default.self_link + priority = 2000 +} +`, context) +} + func testAccCheckComputeRouteDestroy(s *terraform.State) error { for name, rs := range s.RootModule().Resources { if rs.Type != "google_compute_route" { diff --git a/website/docs/r/compute_route.html.markdown b/website/docs/r/compute_route.html.markdown index 3e657e2500e..9dccb4fdec9 100644 --- a/website/docs/r/compute_route.html.markdown +++ b/website/docs/r/compute_route.html.markdown @@ -74,22 +74,20 @@ resource "google_compute_network" "default" { } ``` -## Example Usage - Route Ilb Beta +## Example Usage - Route Ilb ```hcl resource "google_compute_network" "default" { - provider = google-beta name = "compute-network" auto_create_subnetworks = false } resource "google_compute_subnetwork" "default" { - provider = google-beta name = "compute-subnet" ip_cidr_range = "10.0.1.0/24" region = "us-central1" @@ -97,7 +95,6 @@ resource "google_compute_subnetwork" "default" { } resource "google_compute_health_check" "hc" { - provider = google-beta name = "proxy-health-check" check_interval_sec = 1 timeout_sec = 1 @@ -108,14 +105,12 @@ resource "google_compute_health_check" "hc" { } resource "google_compute_region_backend_service" "backend" { - provider = google-beta name = "compute-backend" region = "us-central1" health_checks = [google_compute_health_check.hc.self_link] } resource "google_compute_forwarding_rule" "default" { - provider = google-beta name = "compute-forwarding-rule" region = "us-central1" @@ -126,9 +121,8 @@ resource "google_compute_forwarding_rule" "default" { subnetwork = google_compute_subnetwork.default.name } -resource "google_compute_route" "route-ilb-beta" { - provider = google-beta - name = "route-ilb-beta" +resource "google_compute_route" "route-ilb" { + name = "route-ilb" dest_range = "0.0.0.0/0" network = google_compute_network.default.name next_hop_ilb = google_compute_forwarding_rule.default.self_link @@ -208,6 +202,14 @@ The following arguments are supported: (Optional) URL to a VpnTunnel that should handle matching packets. +* `next_hop_ilb` - + (Optional) + The URL to a forwarding rule of type loadBalancingScheme=INTERNAL that should handle matching packets. + You can only specify the forwarding rule as a partial or full URL. For example, the following are all valid URLs: + https://www.googleapis.com/compute/v1/projects/project/regions/region/forwardingRules/forwardingRule + regions/region/forwardingRules/forwardingRule + Note that this can only be used when the destinationRange is a public (non-RFC 1918) IP CIDR range. + * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.