Skip to content

Commit

Permalink
Add test for global INTERNAL_SELF_MANAGED backend service. Documentat…
Browse files Browse the repository at this point in the history
…ion update
  • Loading branch information
slevenick committed May 28, 2019
1 parent 707c88c commit c337d1a
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
6 changes: 4 additions & 2 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ objects:
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.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation': 'https://cloud.google.com/compute/docs/load-balancing/http/backend-service'
Expand Down
8 changes: 8 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
vars:
backend_service_name: "backend-service"
http_health_check_name: "health-check"
- !ruby/object:Provider::Terraform::Examples
name: "backend_service_global_internal"
min_version: beta
primary_resource_id: "default"
vars:
forwarding_rule_name: "global-rule"
http_proxy_name: "target-proxy"
backend_service_name: "backend"
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/backend_service.go.erb'
encoder: 'templates/terraform/encoders/backend_service.go.erb'
Expand Down
100 changes: 100 additions & 0 deletions templates/terraform/examples/backend_service_global_internal.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
resource "google_compute_global_forwarding_rule" "default" {
provider = "google-beta"
name = "<%= ctx[:vars]['forwarding_rule_name'] %>"
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 = "<%= ctx[:vars]['http_proxy_name'] %>"
description = "a description"
url_map = "${google_compute_url_map.default.self_link}"
}

resource "google_compute_url_map" "default" {
provider = "google-beta"
name = "url-map-<%= ctx[:vars]['http_proxy_name'] %>"
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 = "<%= ctx[:vars]['backend_service_name'] %>"
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-<%= ctx[:vars]['backend_service_name'] %>"
check_interval_sec = 1
timeout_sec = 1

tcp_health_check {
port = "80"
}
}

0 comments on commit c337d1a

Please sign in to comment.