diff --git a/google/resource_compute_forwarding_rule.go b/google/resource_compute_forwarding_rule.go index 644bbf23af7..9b852f1f9cf 100644 --- a/google/resource_compute_forwarding_rule.go +++ b/google/resource_compute_forwarding_rule.go @@ -247,9 +247,8 @@ subnetwork must be specified.`, Type: schema.TypeString, Optional: true, DiffSuppressFunc: compareSelfLinkRelativePaths, - Description: `This field is only used for EXTERNAL load balancing. -A reference to a TargetPool resource to receive the matched traffic. -This target must live in the same region as the forwarding rule. + Description: `The URL of the target resource to receive the matched traffic. +The target must live in the same region as the forwarding rule. The forwarded traffic must be of a type appropriate to the target object.`, }, @@ -650,10 +649,7 @@ func flattenComputeForwardingRuleSubnetwork(v interface{}, d *schema.ResourceDat } func flattenComputeForwardingRuleTarget(v interface{}, d *schema.ResourceData) interface{} { - if v == nil { - return v - } - return ConvertSelfLinkToV1(v.(string)) + return v } func flattenComputeForwardingRuleAllPorts(v interface{}, d *schema.ResourceData) interface{} { diff --git a/google/resource_compute_region_backend_service.go b/google/resource_compute_region_backend_service.go index fe8b0c8c967..64afc56e353 100644 --- a/google/resource_compute_region_backend_service.go +++ b/google/resource_compute_region_backend_service.go @@ -202,13 +202,15 @@ partial URL.`, }, "capacity_scaler": { Type: schema.TypeFloat, - Computed: true, Optional: true, Description: `A multiplier applied to the group's maximum servicing capacity (based on UTILIZATION, RATE or CONNECTION). +Default value is 1, which means the group will serve up to 100% +of its configured capacity (depending on balancingMode). A setting of 0 means the group is completely drained, offering 0% of its available Capacity. Valid range is [0.0,1.0].`, + Default: 1.0, }, "description": { Type: schema.TypeString, @@ -811,7 +813,7 @@ func expandComputeRegionBackendServiceBackend(v interface{}, d TerraformResource transformedCapacityScaler, err := expandComputeRegionBackendServiceBackendCapacityScaler(original["capacity_scaler"], d, config) if err != nil { return nil, err - } else if val := reflect.ValueOf(transformedCapacityScaler); val.IsValid() && !isEmptyValue(val) { + } else { transformed["capacityScaler"] = transformedCapacityScaler } diff --git a/website/docs/r/compute_forwarding_rule.html.markdown b/website/docs/r/compute_forwarding_rule.html.markdown index d3d014bc1aa..4e8ea64470b 100644 --- a/website/docs/r/compute_forwarding_rule.html.markdown +++ b/website/docs/r/compute_forwarding_rule.html.markdown @@ -150,6 +150,204 @@ resource "google_compute_subnetwork" "default" { network = google_compute_network.default.self_link } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Forwarding Rule Http Lb + + +```hcl +// Forwarding rule for Internal Load Balancing +resource "google_compute_forwarding_rule" "default" { + provider = google-beta + depends_on = [google_compute_subnetwork.proxy] + name = "website-forwarding-rule" + region = "us-central1" + + ip_protocol = "TCP" + load_balancing_scheme = "INTERNAL_MANAGED" + port_range = "80" + target = google_compute_region_target_http_proxy.default.self_link + network = google_compute_network.default.self_link + subnetwork = google_compute_subnetwork.default.self_link + network_tier = "PREMIUM" +} + +resource "google_compute_region_target_http_proxy" "default" { + provider = google-beta + + region = "us-central1" + name = "website-proxy" + url_map = google_compute_region_url_map.default.self_link +} + +resource "google_compute_region_url_map" "default" { + provider = google-beta + + region = "us-central1" + name = "website-map" + default_service = google_compute_region_backend_service.default.self_link +} + +resource "google_compute_region_backend_service" "default" { + provider = google-beta + + load_balancing_scheme = "INTERNAL_MANAGED" + + backend { + group = google_compute_region_instance_group_manager.rigm.instance_group + balancing_mode = "UTILIZATION" + } + + region = "us-central1" + name = "website-backend" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = [google_compute_region_health_check.default.self_link] +} + +data "google_compute_image" "debian_image" { + provider = google-beta + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_region_instance_group_manager" "rigm" { + provider = google-beta + region = "us-central1" + name = "rigm-internal" + version { + instance_template = google_compute_instance_template.instance_template.self_link + name = "primary" + } + base_instance_name = "internal-glb" + target_size = 1 +} + +resource "google_compute_instance_template" "instance_template" { + provider = google-beta + name = "template-website-backend" + machine_type = "n1-standard-1" + + network_interface { + network = google_compute_network.default.self_link + subnetwork = google_compute_subnetwork.default.self_link + } + + disk { + source_image = data.google_compute_image.debian_image.self_link + auto_delete = true + boot = true + } + + tags = ["allow-ssh", "load-balanced-backend"] +} + +resource "google_compute_region_health_check" "default" { + depends_on = [google_compute_firewall.fw4] + provider = google-beta + + region = "us-central1" + name = "website-hc" + http_health_check { + port_specification = "USE_SERVING_PORT" + } +} + +resource "google_compute_firewall" "fw1" { + provider = google-beta + name = "website-fw-1" + network = google_compute_network.default.self_link + source_ranges = ["10.1.2.0/24"] + allow { + protocol = "tcp" + } + allow { + protocol = "udp" + } + allow { + protocol = "icmp" + } + direction = "INGRESS" +} + +resource "google_compute_firewall" "fw2" { + depends_on = [google_compute_firewall.fw1] + provider = google-beta + name = "website-fw-2" + network = google_compute_network.default.self_link + source_ranges = ["0.0.0.0/0"] + allow { + protocol = "tcp" + ports = ["22"] + } + target_tags = ["allow-ssh"] + direction = "INGRESS" +} + +resource "google_compute_firewall" "fw3" { + depends_on = [google_compute_firewall.fw2] + provider = google-beta + name = "website-fw-3" + network = google_compute_network.default.self_link + source_ranges = ["130.211.0.0/22", "35.191.0.0/16"] + allow { + protocol = "tcp" + } + target_tags = ["load-balanced-backend"] + direction = "INGRESS" +} + +resource "google_compute_firewall" "fw4" { + depends_on = [google_compute_firewall.fw3] + provider = google-beta + name = "website-fw-4" + network = google_compute_network.default.self_link + source_ranges = ["10.129.0.0/26"] + target_tags = ["load-balanced-backend"] + allow { + protocol = "tcp" + ports = ["80"] + } + allow { + protocol = "tcp" + ports = ["443"] + } + allow { + protocol = "tcp" + ports = ["8000"] + } + direction = "INGRESS" +} + +resource "google_compute_network" "default" { + provider = google-beta + name = "website-net" + auto_create_subnetworks = false + routing_mode = "REGIONAL" +} + +resource "google_compute_subnetwork" "default" { + provider = google-beta + name = "website-net-default" + ip_cidr_range = "10.1.2.0/24" + region = "us-central1" + network = google_compute_network.default.self_link +} + +resource "google_compute_subnetwork" "proxy" { + provider = google-beta + name = "website-net-proxy" + ip_cidr_range = "10.129.0.0/26" + region = "us-central1" + network = google_compute_network.default.self_link + purpose = "INTERNAL_HTTPS_LOAD_BALANCER" + role = "ACTIVE" +} +``` ## Argument Reference @@ -266,9 +464,8 @@ The following arguments are supported: * `target` - (Optional) - This field is only used for EXTERNAL load balancing. - A reference to a TargetPool resource to receive the matched traffic. - This target must live in the same region as the forwarding rule. + The URL of the target resource to receive the matched traffic. + The target must live in the same region as the forwarding rule. The forwarded traffic must be of a type appropriate to the target object. diff --git a/website/docs/r/compute_region_backend_service.html.markdown b/website/docs/r/compute_region_backend_service.html.markdown index 744a722d6bb..6dd71cad0b5 100644 --- a/website/docs/r/compute_region_backend_service.html.markdown +++ b/website/docs/r/compute_region_backend_service.html.markdown @@ -134,6 +134,100 @@ resource "google_compute_health_check" "health_check" { } } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Region Backend Service Balancing Mode + + +```hcl +resource "google_compute_region_backend_service" "default" { + provider = google-beta + + load_balancing_scheme = "INTERNAL_MANAGED" + + backend { + group = google_compute_region_instance_group_manager.rigm.instance_group + balancing_mode = "UTILIZATION" + } + + region = "us-central1" + name = "region-backend-service" + protocol = "HTTP" + timeout_sec = 10 + + health_checks = [google_compute_region_health_check.default.self_link] +} + +data "google_compute_image" "debian_image" { + provider = google-beta + + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_region_instance_group_manager" "rigm" { + provider = google-beta + + region = "us-central1" + name = "rigm-internal" + version { + instance_template = google_compute_instance_template.instance_template.self_link + name = "primary" + } + base_instance_name = "internal-glb" + target_size = 1 +} + +resource "google_compute_instance_template" "instance_template" { + provider = google-beta + + name = "template-region-backend-service" + machine_type = "n1-standard-1" + + network_interface { + network = google_compute_network.default.self_link + subnetwork = google_compute_subnetwork.default.self_link + } + + disk { + source_image = data.google_compute_image.debian_image.self_link + auto_delete = true + boot = true + } + + tags = ["allow-ssh", "load-balanced-backend"] +} + +resource "google_compute_region_health_check" "default" { + provider = google-beta + + region = "us-central1" + name = "health-check" + http_health_check { + port_specification = "USE_SERVING_PORT" + } +} + +resource "google_compute_network" "default" { + provider = google-beta + + name = "net" + auto_create_subnetworks = false + routing_mode = "REGIONAL" +} + +resource "google_compute_subnetwork" "default" { + provider = google-beta + + name = "net-default" + ip_cidr_range = "10.1.2.0/24" + region = "us-central1" + network = google_compute_network.default.self_link +} +``` ## Argument Reference @@ -216,6 +310,8 @@ The `backend` block supports: (Optional) A multiplier applied to the group's maximum servicing capacity (based on UTILIZATION, RATE or CONNECTION). + Default value is 1, which means the group will serve up to 100% + of its configured capacity (depending on balancingMode). A setting of 0 means the group is completely drained, offering 0% of its available Capacity. Valid range is [0.0,1.0].