diff --git a/google/resource_compute_backend_service.go b/google/resource_compute_backend_service.go index bc5cf335253..380ddcdb8d1 100644 --- a/google/resource_compute_backend_service.go +++ b/google/resource_compute_backend_service.go @@ -254,7 +254,7 @@ func resourceComputeBackendService() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"EXTERNAL", ""}, false), + ValidateFunc: validation.StringInSlice([]string{"EXTERNAL", "INTERNAL_SELF_MANAGED", ""}, false), Default: "EXTERNAL", }, "port_name": { diff --git a/google/resource_compute_global_forwarding_rule.go b/google/resource_compute_global_forwarding_rule.go index 14939fbcfcc..75816b289d6 100644 --- a/google/resource_compute_global_forwarding_rule.go +++ b/google/resource_compute_global_forwarding_rule.go @@ -78,6 +78,13 @@ func resourceComputeGlobalForwardingRule() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"IPV4", "IPV6", ""}, false), }, + "load_balancing_scheme": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"INTERNAL_SELF_MANAGED", "EXTERNAL", ""}, false), + Default: "EXTERNAL", + }, "port_range": { Type: schema.TypeString, Optional: true, @@ -126,6 +133,12 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("ip_version"); !isEmptyValue(reflect.ValueOf(ipVersionProp)) && (ok || !reflect.DeepEqual(v, ipVersionProp)) { obj["ipVersion"] = ipVersionProp } + loadBalancingSchemeProp, err := expandComputeGlobalForwardingRuleLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("load_balancing_scheme"); !isEmptyValue(reflect.ValueOf(loadBalancingSchemeProp)) && (ok || !reflect.DeepEqual(v, loadBalancingSchemeProp)) { + obj["loadBalancingScheme"] = loadBalancingSchemeProp + } nameProp, err := expandComputeGlobalForwardingRuleName(d.Get("name"), d, config) if err != nil { return err @@ -221,6 +234,9 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf if err := d.Set("ip_version", flattenComputeGlobalForwardingRuleIpVersion(res["ipVersion"], d)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } + if err := d.Set("load_balancing_scheme", flattenComputeGlobalForwardingRuleLoadBalancingScheme(res["loadBalancingScheme"], d)); err != nil { + return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) + } if err := d.Set("name", flattenComputeGlobalForwardingRuleName(res["name"], d)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } @@ -355,6 +371,10 @@ func flattenComputeGlobalForwardingRuleIpVersion(v interface{}, d *schema.Resour return v } +func flattenComputeGlobalForwardingRuleLoadBalancingScheme(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenComputeGlobalForwardingRuleName(v interface{}, d *schema.ResourceData) interface{} { return v } @@ -383,6 +403,10 @@ func expandComputeGlobalForwardingRuleIpVersion(v interface{}, d TerraformResour return v, nil } +func expandComputeGlobalForwardingRuleLoadBalancingScheme(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandComputeGlobalForwardingRuleName(v interface{}, d TerraformResourceData, config *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 3338fc965cc..21b127897d9 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -24,8 +24,10 @@ description: |- A Backend Service defines a group of virtual machines that will serve traffic for load balancing. This resource is a global backend service, -appropriate for external load balancing. For internal load balancing, use -a regional backend service instead. +appropriate for external load balancing or self-managed internal load balancing. +For managed internal load balancing, use a regional backend service instead. + +Currently self-managed internal load balancing is only available in beta. To get more information about BackendService, see: @@ -66,6 +68,7 @@ The following arguments are supported: The list of URLs to the HttpHealthCheck or HttpsHealthCheck resource for health checking this BackendService. Currently at most one health check can be specified, and a health check is required. + For internal load balancing, a URL to a HealthCheck resource must be specified instead. * `name` - (Required) @@ -118,8 +121,8 @@ The following arguments are supported: (Optional) 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. Must be `EXTERNAL` for - a global backend service. Defaults to `EXTERNAL`. + load balancing cannot be used with the other. Must be `EXTERNAL` or + `INTERNAL_SELF_MANAGED` for a global backend service. Defaults to `EXTERNAL`. * `port_name` - (Optional) diff --git a/website/docs/r/compute_global_forwarding_rule.html.markdown b/website/docs/r/compute_global_forwarding_rule.html.markdown index f1db1e4eef6..b13baed829f 100644 --- a/website/docs/r/compute_global_forwarding_rule.html.markdown +++ b/website/docs/r/compute_global_forwarding_rule.html.markdown @@ -89,6 +89,116 @@ resource "google_compute_http_health_check" "default" { timeout_sec = 1 } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Global Forwarding Rule Internal + + +```hcl +resource "google_compute_global_forwarding_rule" "default" { + provider = "google-beta" + name = "global-rule" + target = "${google_compute_target_http_proxy.default.self_link}" + port_range = "80" + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + ip_address = "0.0.0.0" +} + +resource "google_compute_target_http_proxy" "default" { + provider = "google-beta" + name = "target-proxy" + description = "a description" + url_map = "${google_compute_url_map.default.self_link}" +} + +resource "google_compute_url_map" "default" { + provider = "google-beta" + name = "url-map-target-proxy" + description = "a description" + default_service = "${google_compute_backend_service.default.self_link}" + + host_rule { + hosts = ["mysite.com"] + path_matcher = "allpaths" + } + + path_matcher { + name = "allpaths" + default_service = "${google_compute_backend_service.default.self_link}" + + path_rule { + paths = ["/*"] + service = "${google_compute_backend_service.default.self_link}" + } + } +} + +resource "google_compute_backend_service" "default" { + provider = "google-beta" + name = "backend" + port_name = "http" + protocol = "HTTP" + timeout_sec = 10 + load_balancing_scheme = "INTERNAL_SELF_MANAGED" + + backend { + group = "${google_compute_instance_group_manager.foobar.instance_group}" + balancing_mode = "RATE" + capacity_scaler = 0.4 + max_rate_per_instance = 50 + } + + health_checks = ["${google_compute_health_check.default.self_link}"] +} + +data "google_compute_image" "debian_image" { + provider = "google-beta" + family = "debian-9" + project = "debian-cloud" +} + +resource "google_compute_instance_group_manager" "foobar" { + provider = "google-beta" + name = "igm-internal" + version { + instance_template = "${google_compute_instance_template.foobar.self_link}" + name = "primary" + } + base_instance_name = "foobar" + zone = "us-central1-f" + target_size = 1 +} + +resource "google_compute_instance_template" "foobar" { + provider = "google-beta" + name = "instance-template-internal" + machine_type = "n1-standard-1" + + network_interface { + network = "default" + } + + disk { + source_image = "${data.google_compute_image.debian_image.self_link}" + auto_delete = true + boot = true + } +} + +resource "google_compute_health_check" "default" { + provider = "google-beta" + name = "check-backend" + check_interval_sec = 1 + timeout_sec = 1 + + tcp_health_check { + port = "80" + } +} +``` ## Argument Reference @@ -153,6 +263,16 @@ The following arguments are supported: The IP Version that will be used by this global forwarding rule. Valid options are IPV4 or IPV6. +* `load_balancing_scheme` - + (Optional) + This signifies what the GlobalForwardingRule will be used for. + The value of INTERNAL_SELF_MANAGED means that this will be used for + Internal Global HTTP(S) LB. The value of EXTERNAL means that this + will be used for External Global Load Balancing (HTTP(S) LB, + External TCP/UDP LB, SSL Proxy) + NOTE: Currently global forwarding rules cannot be used for INTERNAL + load balancing. + * `port_range` - (Optional) This field is used along with the target field for TargetHttpProxy,