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 new resource "Service LB Policy" to the provider #18326

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
29 changes: 29 additions & 0 deletions google/services/compute/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,12 @@ alt name matches one of the specified values.`,
},
},
},
"service_lb_policy": {
Type: schema.TypeString,
Optional: true,
Description: `URL to networkservices.ServiceLbPolicy resource.
Can only be set if load balancing scheme is EXTERNAL, EXTERNAL_MANAGED, INTERNAL_MANAGED or INTERNAL_SELF_MANAGED and the scope is global.`,
},
"session_affinity": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1409,6 +1415,12 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOkExists("log_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(logConfigProp)) && (ok || !reflect.DeepEqual(v, logConfigProp)) {
obj["logConfig"] = logConfigProp
}
serviceLbPolicyProp, err := expandComputeBackendServiceServiceLbPolicy(d.Get("service_lb_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_lb_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceLbPolicyProp)) && (ok || !reflect.DeepEqual(v, serviceLbPolicyProp)) {
obj["serviceLbPolicy"] = serviceLbPolicyProp
}

obj, err = resourceComputeBackendServiceEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -1663,6 +1675,9 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
if err := d.Set("log_config", flattenComputeBackendServiceLogConfig(res["logConfig"], d, config)); err != nil {
return fmt.Errorf("Error reading BackendService: %s", err)
}
if err := d.Set("service_lb_policy", flattenComputeBackendServiceServiceLbPolicy(res["serviceLbPolicy"], d, config)); err != nil {
return fmt.Errorf("Error reading BackendService: %s", err)
}
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading BackendService: %s", err)
}
Expand Down Expand Up @@ -1848,6 +1863,12 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOkExists("log_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, logConfigProp)) {
obj["logConfig"] = logConfigProp
}
serviceLbPolicyProp, err := expandComputeBackendServiceServiceLbPolicy(d.Get("service_lb_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("service_lb_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, serviceLbPolicyProp)) {
obj["serviceLbPolicy"] = serviceLbPolicyProp
}

obj, err = resourceComputeBackendServiceEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -3187,6 +3208,10 @@ func flattenComputeBackendServiceLogConfigSampleRate(v interface{}, d *schema.Re
return v
}

func flattenComputeBackendServiceServiceLbPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandComputeBackendServiceAffinityCookieTtlSec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -4254,6 +4279,10 @@ func expandComputeBackendServiceLogConfigSampleRate(v interface{}, d tpgresource
return v, nil
}

func expandComputeBackendServiceServiceLbPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func resourceComputeBackendServiceEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// The BackendService API's Update / PUT API is badly formed and behaves like
// a PATCH field for at least IAP. When sent a `null` `iap` field, the API
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package networkservices_test
5 changes: 5 additions & 0 deletions website/docs/r/compute_backend_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ The following arguments are supported:
If logging is enabled, logs will be exported to Stackdriver.
Structure is [documented below](#nested_log_config).

* `service_lb_policy` -
(Optional)
URL to networkservices.ServiceLbPolicy resource.
Can only be set if load balancing scheme is EXTERNAL, EXTERNAL_MANAGED, INTERNAL_MANAGED or INTERNAL_SELF_MANAGED and the scope is global.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down
201 changes: 201 additions & 0 deletions website/docs/r/network_services_service_lb_policies.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Network services"
description: |-
ServiceLbPolicy holds global load balancing and traffic distribution configuration that can be applied to a BackendService.
---

# google_network_services_service_lb_policies

ServiceLbPolicy holds global load balancing and traffic distribution configuration that can be applied to a BackendService.

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.


<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%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=network_services_service_lb_policies_basic&open_in_editor=main.tf" 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 - Network Services Service Lb Policies Basic


```hcl
resource "google_network_services_service_lb_policies" "default" {
provider = google-beta

name = "my-lb-policy"
location = "global"
}
```
<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%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=network_services_service_lb_policies_advanced&open_in_editor=main.tf" 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 - Network Services Service Lb Policies Advanced


```hcl
resource "google_network_services_service_lb_policies" "default" {
provider = google-beta

name = "my-lb-policy"
location = "global"
description = "my description"
load_balancing_algorithm = "SPRAY_TO_REGION"

auto_capacity_drain {
enable = true
}

failover_config {
failover_health_threshold = 70
}

labels = {
foo = "bar"
}
}

resource "google_compute_backend_service" "default" {
provider = google-beta

name = "my-lb-backend"
description = "my description"
load_balancing_scheme = "INTERNAL_SELF_MANAGED"
protocol = "HTTP"
service_lb_policy = "//networkservices.googleapis.com/${google_network_services_service_lb_policies.default.id}"
}
```

## Argument Reference

The following arguments are supported:


* `name` -
(Required)
Name of the ServiceLbPolicy resource. It matches pattern `projects/{project}/locations/{location}/serviceLbPolicies/{service_lb_policy_name}`.

* `location` -
(Required)
The location of the service lb policy.


- - -


* `labels` -
(Optional)
Set of label tags associated with the ServiceLbPolicy resource.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field `effective_labels` for all of the labels present on the resource.

* `description` -
(Optional)
A free-text description of the resource. Max length 1024 characters.

* `load_balancing_algorithm` -
(Optional)
The type of load balancing algorithm to be used. The default behavior is WATERFALL_BY_REGION.
Possible values are: `SPRAY_TO_REGION`, `SPRAY_TO_WORLD`, `WATERFALL_BY_REGION`, `WATERFALL_BY_ZONE`.

* `auto_capacity_drain` -
(Optional)
Option to specify if an unhealthy MIG/NEG should be considered for global load balancing and traffic routing.
Structure is [documented below](#nested_auto_capacity_drain).

* `failover_config` -
(Optional)
Option to specify health based failover behavior. This is not related to Network load balancer FailoverPolicy.
Structure is [documented below](#nested_failover_config).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.


<a name="nested_auto_capacity_drain"></a>The `auto_capacity_drain` block supports:

* `enable` -
(Optional)
Optional. If set to 'True', an unhealthy MIG/NEG will be set as drained. - An MIG/NEG is considered unhealthy if less than 25% of the instances/endpoints in the MIG/NEG are healthy. - This option will never result in draining more than 50% of the configured IGs/NEGs for the Backend Service.

<a name="nested_failover_config"></a>The `failover_config` block supports:

* `failover_health_threshold` -
(Required)
Optional. The percentage threshold that a load balancer will begin to send traffic to failover backends. If the percentage of endpoints in a MIG/NEG is smaller than this value, traffic would be sent to failover backends if possible. This field should be set to a value between 1 and 99. The default value is 50 for Global external HTTP(S) load balancer (classic) and Proxyless service mesh, and 70 for others.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/serviceLbPolicies/{{name}}`

* `create_time` -
Time the ServiceLbPolicy was created in UTC.

* `update_time` -
Time the ServiceLbPolicy was updated in UTC.

* `terraform_labels` -
The combination of labels configured directly on the resource
and default labels configured on the provider.

* `effective_labels` -
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.


## Timeouts

This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:

- `create` - Default is 30 minutes.
- `update` - Default is 30 minutes.
- `delete` - Default is 30 minutes.

## Import


ServiceLbPolicies can be imported using any of these accepted formats:

* `projects/{{project}}/locations/{{location}}/serviceLbPolicies/{{name}}`
* `{{project}}/{{location}}/{{name}}`
* `{{location}}/{{name}}`


In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import ServiceLbPolicies using one of the formats above. For example:

```tf
import {
id = "projects/{{project}}/locations/{{location}}/serviceLbPolicies/{{name}}"
to = google_network_services_service_lb_policies.default
}
```

When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), ServiceLbPolicies can be imported using one of the formats above. For example:

```
$ terraform import google_network_services_service_lb_policies.default projects/{{project}}/locations/{{location}}/serviceLbPolicies/{{name}}
$ terraform import google_network_services_service_lb_policies.default {{project}}/{{location}}/{{name}}
$ terraform import google_network_services_service_lb_policies.default {{location}}/{{name}}
```

## User Project Overrides

This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).