Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for INTERNAL_SELF_MANAGED backend service #1833

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,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 Expand Up @@ -799,6 +801,8 @@ objects:
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.
- !ruby/object:Api::Type::Integer
name: 'id'
description: 'The unique identifier for the resource.'
Expand Down Expand Up @@ -831,14 +835,15 @@ objects:
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. 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`.
default_value: :EXTERNAL
# If you're modifying this value, it probably means Global ILB is now
# an option. If that's the case, all of the documentation is based on
# this resource supporting external load balancing only.
values:
- :EXTERNAL
- :INTERNAL_SELF_MANAGED
- !ruby/object:Api::Type::String
name: 'name'
required: true
Expand Down Expand Up @@ -2296,6 +2301,7 @@ objects:

NOTE: Currently global forwarding rules cannot be used for INTERNAL
load balancing.
default_value: :EXTERNAL
values:
- :INTERNAL_SELF_MANAGED
- :EXTERNAL
Expand Down
13 changes: 10 additions & 3 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
forwarding_rule_name: "global-rule"
http_proxy_name: "target-proxy"
backend_service_name: "backend"
- !ruby/object:Provider::Terraform::Examples
name: "global_forwarding_rule_internal"
min_version: beta
primary_resource_id: "default"
vars:
forwarding_rule_name: "global-rule"
http_proxy_name: "target-proxy"
backend_service_name: "backend"
properties:
creationTimestamp: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
Expand All @@ -543,10 +551,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides
IPProtocol: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'caseDiffSuppress'
default_from_api: true
loadBalancingScheme: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
network: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
default_from_api: true
min_version: beta
portRange: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'portRangeDiffSuppress'
target: !ruby/object:Overrides::Terraform::PropertyOverride
Expand Down
100 changes: 100 additions & 0 deletions templates/terraform/examples/global_forwarding_rule_internal.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
resource "google_compute_global_forwarding_rule" "default" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,34 @@ func TestAccComputeBackendService_withCustomHeaders(t *testing.T) {
}
<% end -%>

<% unless version == 'ga' -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hand-written test is only necessary in order to do the import part, right? If so, can you add a comment to remove it once the feature goes GA (since then we'd get import for the example test)?

func TestAccComputeBackendService_internalLoadBalancing(t *testing.T) {
t.Parallel()

fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
proxy := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeBackendService_internalLoadBalancing(fr, proxy, backend, hc, urlmap),
},
{
ResourceName: "google_compute_backend_service.backend_service",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
<% end -%>

func testAccComputeBackendService_basic(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_backend_service" "foobar" {
Expand Down Expand Up @@ -1078,3 +1106,102 @@ resource "google_compute_http_health_check" "zero" {
`, serviceName, checkName)
}
<% end -%>

<% unless version == 'ga' -%>
<%# This test is for import functionality. It can be removed and added to examples when this goes GA %>
func testAccComputeBackendService_internalLoadBalancing(fr, proxy, backend, hc, urlmap string) string {
return fmt.Sprintf(`
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
name = "%s"
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" {
name = "%s"
description = "a description"
url_map = "${google_compute_url_map.default.self_link}"
}

resource "google_compute_backend_service" "backend_service" {
name = "%s"
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}"]
}

resource "google_compute_health_check" "default" {
name = "%s"
check_interval_sec = 1
timeout_sec = 1

tcp_health_check {
port = "80"
}
}

resource "google_compute_url_map" "default" {
name = "%s"
description = "a description"
default_service = "${google_compute_backend_service.backend_service.self_link}"

host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}

path_matcher {
name = "allpaths"
default_service = "${google_compute_backend_service.backend_service.self_link}"

path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.backend_service.self_link}"
}
}
}

data "google_compute_image" "debian_image" {
family = "debian-9"
project = "debian-cloud"
}

resource "google_compute_instance_group_manager" "foobar" {
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" {
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
}
}`, fr, proxy, backend, hc, urlmap)
}
<% end -%>
Loading