Skip to content

Commit

Permalink
Add support for INTERNAL_SELF_MANAGED backend service
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
slevenick authored and modular-magician committed May 29, 2019
1 parent 60643be commit 6fb7685
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 5 deletions.
2 changes: 1 addition & 1 deletion google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 24 additions & 0 deletions google/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
120 changes: 120 additions & 0 deletions website/docs/r/compute_global_forwarding_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,116 @@ resource "google_compute_http_health_check" "default" {
timeout_sec = 1
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=global_forwarding_rule_internal&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6fb7685

Please sign in to comment.