diff --git a/.changelog/8566.txt b/.changelog/8566.txt new file mode 100644 index 00000000000..09f14d89c20 --- /dev/null +++ b/.changelog/8566.txt @@ -0,0 +1,9 @@ +```release-note:enhancement +compute: added support for INTERNAL_MANAGED to the filed `load_balancing_scheme` in the resource `google_compute_backend_service` +``` +```release-note:enhancement +compute: added support for INTERNAL_MANAGED to the filed `load_balancing_scheme` in the resource `google_compute_global_forwarding_rule` +``` +```release-note:enhancement +compute: added `subnetwork` field to the resource `google_compute_global_forwarding_rule` +``` diff --git a/google/resource_compute_global_forwarding_rule_generated_test.go b/google/resource_compute_global_forwarding_rule_generated_test.go index 65904f8e960..1499247eb36 100644 --- a/google/resource_compute_global_forwarding_rule_generated_test.go +++ b/google/resource_compute_global_forwarding_rule_generated_test.go @@ -49,7 +49,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(t *testi ResourceName: "google_compute_global_forwarding_rule.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"}, + ImportStateVerifyIgnore: []string{"network", "subnetwork", "no_automate_dns_zone", "port_range", "target"}, }, }, }) @@ -127,7 +127,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleExternalManagedExamp ResourceName: "google_compute_global_forwarding_rule.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"}, + ImportStateVerifyIgnore: []string{"network", "subnetwork", "no_automate_dns_zone", "port_range", "target"}, }, }, }) @@ -198,7 +198,7 @@ func TestAccComputeGlobalForwardingRule_globalForwardingRuleHybridExample(t *tes ResourceName: "google_compute_global_forwarding_rule.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"network", "no_automate_dns_zone", "port_range", "target"}, + ImportStateVerifyIgnore: []string{"network", "subnetwork", "no_automate_dns_zone", "port_range", "target"}, }, }, }) diff --git a/google/services/compute/resource_compute_backend_service.go b/google/services/compute/resource_compute_backend_service.go index b43f4389971..6f8fcd062d6 100644 --- a/google/services/compute/resource_compute_backend_service.go +++ b/google/services/compute/resource_compute_backend_service.go @@ -656,11 +656,11 @@ For internal load balancing, a URL to a HealthCheck resource must be specified i Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: verify.ValidateEnum([]string{"EXTERNAL", "INTERNAL_SELF_MANAGED", "EXTERNAL_MANAGED", ""}), + ValidateFunc: verify.ValidateEnum([]string{"EXTERNAL", "INTERNAL_SELF_MANAGED", "INTERNAL_MANAGED", "EXTERNAL_MANAGED", ""}), Description: `Indicates whether the backend service will be used with internal or external load balancing. A backend service created for one type of load balancing cannot be used with the other. For more information, refer to -[Choosing a load balancer](https://cloud.google.com/load-balancing/docs/backend-service). Default value: "EXTERNAL" Possible values: ["EXTERNAL", "INTERNAL_SELF_MANAGED", "EXTERNAL_MANAGED"]`, +[Choosing a load balancer](https://cloud.google.com/load-balancing/docs/backend-service). Default value: "EXTERNAL" Possible values: ["EXTERNAL", "INTERNAL_SELF_MANAGED", "INTERNAL_MANAGED", "EXTERNAL_MANAGED"]`, Default: "EXTERNAL", }, "locality_lb_policies": { diff --git a/google/services/compute/resource_compute_global_forwarding_rule.go b/google/services/compute/resource_compute_global_forwarding_rule.go index d9154e7c260..8fc9232f050 100644 --- a/google/services/compute/resource_compute_global_forwarding_rule.go +++ b/google/services/compute/resource_compute_global_forwarding_rule.go @@ -174,11 +174,11 @@ you create the resource.`, Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: verify.ValidateEnum([]string{"EXTERNAL", "EXTERNAL_MANAGED", "INTERNAL_SELF_MANAGED", ""}), + ValidateFunc: verify.ValidateEnum([]string{"EXTERNAL", "EXTERNAL_MANAGED", "INTERNAL_MANAGED", "INTERNAL_SELF_MANAGED", ""}), Description: `Specifies the forwarding rule type. For more information about forwarding rules, refer to -[Forwarding rule concepts](https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts). Default value: "EXTERNAL" Possible values: ["EXTERNAL", "EXTERNAL_MANAGED", "INTERNAL_SELF_MANAGED"]`, +[Forwarding rule concepts](https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts). Default value: "EXTERNAL" Possible values: ["EXTERNAL", "EXTERNAL_MANAGED", "INTERNAL_MANAGED", "INTERNAL_SELF_MANAGED"]`, Default: "EXTERNAL", }, "metadata_filters": { @@ -305,6 +305,20 @@ for details. Type: schema.TypeString, }, }, + "subnetwork": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `This field identifies the subnetwork that the load balanced IP should +belong to for this Forwarding Rule, used in internal load balancing and +network load balancing with IPv6. + +If the network specified is in auto subnet mode, this field is optional. +However, a subnetwork must be specified if the network is in custom subnet +mode or when creating external forwarding rule with IPv6.`, + }, "base_forwarding_rule": { Type: schema.TypeString, Computed: true, @@ -415,6 +429,12 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("port_range"); !tpgresource.IsEmptyValue(reflect.ValueOf(portRangeProp)) && (ok || !reflect.DeepEqual(v, portRangeProp)) { obj["portRange"] = portRangeProp } + subnetworkProp, err := expandComputeGlobalForwardingRuleSubnetwork(d.Get("subnetwork"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("subnetwork"); !tpgresource.IsEmptyValue(reflect.ValueOf(subnetworkProp)) && (ok || !reflect.DeepEqual(v, subnetworkProp)) { + obj["subnetwork"] = subnetworkProp + } targetProp, err := expandComputeGlobalForwardingRuleTarget(d.Get("target"), d, config) if err != nil { return err @@ -613,6 +633,9 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf if err := d.Set("port_range", flattenComputeGlobalForwardingRulePortRange(res["portRange"], d, config)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } + if err := d.Set("subnetwork", flattenComputeGlobalForwardingRuleSubnetwork(res["subnetwork"], d, config)); err != nil { + return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) + } if err := d.Set("target", flattenComputeGlobalForwardingRuleTarget(res["target"], d, config)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } @@ -920,6 +943,13 @@ func flattenComputeGlobalForwardingRulePortRange(v interface{}, d *schema.Resour return v } +func flattenComputeGlobalForwardingRuleSubnetwork(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + return tpgresource.ConvertSelfLinkToV1(v.(string)) +} + func flattenComputeGlobalForwardingRuleTarget(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -1053,6 +1083,14 @@ func expandComputeGlobalForwardingRulePortRange(v interface{}, d tpgresource.Ter return v, nil } +func expandComputeGlobalForwardingRuleSubnetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + f, err := tpgresource.ParseRegionalFieldValue("subnetworks", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for subnetwork: %s", err) + } + return f.RelativeLink(), nil +} + func expandComputeGlobalForwardingRuleTarget(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index e3219310e72..2085a52097d 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -436,7 +436,7 @@ The following arguments are supported: load balancing cannot be used with the other. For more information, refer to [Choosing a load balancer](https://cloud.google.com/load-balancing/docs/backend-service). Default value is `EXTERNAL`. - Possible values are: `EXTERNAL`, `INTERNAL_SELF_MANAGED`, `EXTERNAL_MANAGED`. + Possible values are: `EXTERNAL`, `INTERNAL_SELF_MANAGED`, `INTERNAL_MANAGED`, `EXTERNAL_MANAGED`. * `locality_lb_policy` - (Optional) diff --git a/website/docs/r/compute_global_forwarding_rule.html.markdown b/website/docs/r/compute_global_forwarding_rule.html.markdown index e6febd8fb83..56c18a0b7ee 100644 --- a/website/docs/r/compute_global_forwarding_rule.html.markdown +++ b/website/docs/r/compute_global_forwarding_rule.html.markdown @@ -903,6 +903,199 @@ resource "google_compute_global_forwarding_rule" "default" { port_range = "80" } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Global Internal Http Lb With Mig Backend + + +```hcl +# Global Internal HTTP load balancer with a managed instance group backend + +# VPC network +resource "google_compute_network" "gilb_network" { + name = "l7-gilb-network" + provider = google-beta + auto_create_subnetworks = false +} + +# proxy-only subnet +resource "google_compute_subnetwork" "proxy_subnet" { + name = "l7-gilb-proxy-subnet" + provider = google-beta + ip_cidr_range = "10.0.0.0/24" + region = "europe-west1" + purpose = "GLOBAL_MANAGED_PROXY" + role = "ACTIVE" + network = google_compute_network.gilb_network.id +} + +# backend subnet +resource "google_compute_subnetwork" "gilb_subnet" { + name = "l7-gilb-subnet" + provider = google-beta + ip_cidr_range = "10.0.1.0/24" + region = "europe-west1" + network = google_compute_network.gilb_network.id +} + +# forwarding rule +resource "google_compute_global_forwarding_rule" "google_compute_forwarding_rule" { + name = "l7-gilb-forwarding-rule" + provider = google-beta + depends_on = [google_compute_subnetwork.proxy_subnet] + ip_protocol = "TCP" + load_balancing_scheme = "INTERNAL_MANAGED" + port_range = "80" + target = google_compute_target_http_proxy.default.id + network = google_compute_network.gilb_network.id + subnetwork = google_compute_subnetwork.gilb_subnet.id +} + +# HTTP target proxy +resource "google_compute_target_http_proxy" "default" { + name = "l7-gilb-target-http-proxy" + provider = google-beta + url_map = google_compute_url_map.default.id +} + +# URL map +resource "google_compute_url_map" "default" { + name = "l7-gilb-url-map" + provider = google-beta + default_service = google_compute_backend_service.default.id +} + +# backend service +resource "google_compute_backend_service" "default" { + name = "l7-gilb-backend-subnet" + provider = google-beta + protocol = "HTTP" + load_balancing_scheme = "INTERNAL_MANAGED" + timeout_sec = 10 + health_checks = [google_compute_health_check.default.id] + backend { + group = google_compute_instance_group_manager.mig.instance_group + balancing_mode = "UTILIZATION" + capacity_scaler = 1.0 + } +} + +# instance template +resource "google_compute_instance_template" "instance_template" { + name = "l7-gilb-mig-template" + provider = google-beta + machine_type = "e2-small" + tags = ["http-server"] + + network_interface { + network = google_compute_network.gilb_network.id + subnetwork = google_compute_subnetwork.gilb_subnet.id + access_config { + # add external ip to fetch packages + } + } + disk { + source_image = "debian-cloud/debian-10" + auto_delete = true + boot = true + } + + # install nginx and serve a simple web page + metadata = { + startup-script = <<-EOF1 + #! /bin/bash + set -euo pipefail + + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y nginx-light jq + + NAME=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/hostname") + IP=$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip") + METADATA=$(curl -f -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/?recursive=True" | jq 'del(.["startup-script"])') + + cat < /var/www/html/index.html +
+      Name: $NAME
+      IP: $IP
+      Metadata: $METADATA
+      
+ EOF + EOF1 + } + lifecycle { + create_before_destroy = true + } +} + +# health check +resource "google_compute_health_check" "default" { + name = "l7-gilb-hc" + provider = google-beta + http_health_check { + port_specification = "USE_SERVING_PORT" + } +} + +# MIG +resource "google_compute_instance_group_manager" "mig" { + name = "l7-gilb-mig1" + provider = google-beta + zone = "europe-west1-b" + version { + instance_template = google_compute_instance_template.instance_template.id + name = "primary" + } + base_instance_name = "vm" + target_size = 2 +} + +# allow all access from IAP and health check ranges +resource "google_compute_firewall" "fw-iap" { + name = "l7-gilb-fw-allow-iap-hc" + provider = google-beta + direction = "INGRESS" + network = google_compute_network.gilb_network.id + source_ranges = ["130.211.0.0/22", "35.191.0.0/16", "35.235.240.0/20"] + allow { + protocol = "tcp" + } +} + +# allow http from proxy subnet to backends +resource "google_compute_firewall" "fw-gilb-to-backends" { + name = "l7-gilb-fw-allow-gilb-to-backends" + provider = google-beta + direction = "INGRESS" + network = google_compute_network.gilb_network.id + source_ranges = ["10.0.0.0/24"] + target_tags = ["http-server"] + allow { + protocol = "tcp" + ports = ["80", "443", "8080"] + } +} + +# test instance +resource "google_compute_instance" "vm-test" { + name = "l7-gilb-test-vm" + provider = google-beta + zone = "europe-west1-b" + machine_type = "e2-small" + network_interface { + network = google_compute_network.gilb_network.id + subnetwork = google_compute_subnetwork.gilb_subnet.id + } + boot_disk { + initialize_params { + image = "debian-cloud/debian-10" + } + } +} +``` ## Example Usage - Private Service Connect Google Apis @@ -1092,7 +1285,7 @@ The following arguments are supported: For more information about forwarding rules, refer to [Forwarding rule concepts](https://cloud.google.com/load-balancing/docs/forwarding-rule-concepts). Default value is `EXTERNAL`. - Possible values are: `EXTERNAL`, `EXTERNAL_MANAGED`, `INTERNAL_SELF_MANAGED`. + Possible values are: `EXTERNAL`, `EXTERNAL_MANAGED`, `INTERNAL_MANAGED`, `INTERNAL_SELF_MANAGED`. * `metadata_filters` - (Optional) @@ -1142,6 +1335,15 @@ The following arguments are supported: 1883, 5222 * TargetVpnGateway: 500, 4500 +* `subnetwork` - + (Optional) + This field identifies the subnetwork that the load balanced IP should + belong to for this Forwarding Rule, used in internal load balancing and + network load balancing with IPv6. + If the network specified is in auto subnet mode, this field is optional. + However, a subnetwork must be specified if the network is in custom subnet + mode or when creating external forwarding rule with IPv6. + * `source_ip_ranges` - (Optional) If not empty, this Forwarding Rule will only forward the traffic when the source IP address matches one of the IP addresses or CIDR ranges set here. Note that a Forwarding Rule can only have up to 64 source IP ranges, and this field can only be used with a regional Forwarding Rule whose scheme is EXTERNAL. Each sourceIpRange entry should be either an IP address (for example, 1.2.3.4) or a CIDR range (for example, 1.2.3.0/24).