diff --git a/google/services/compute/resource_compute_backend_service.go b/google/services/compute/resource_compute_backend_service.go index a2c4cafd841..0ab312982b9 100644 --- a/google/services/compute/resource_compute_backend_service.go +++ b/google/services/compute/resource_compute_backend_service.go @@ -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, @@ -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 { @@ -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) } @@ -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 { @@ -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 } @@ -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 diff --git a/google/services/networkservices/resource_network_services_service_lb_policies_test.go b/google/services/networkservices/resource_network_services_service_lb_policies_test.go new file mode 100644 index 00000000000..daebda14f01 --- /dev/null +++ b/google/services/networkservices/resource_network_services_service_lb_policies_test.go @@ -0,0 +1,3 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package networkservices_test diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index f6304a9cb21..4a3cafcef80 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -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. diff --git a/website/docs/r/network_services_service_lb_policies.html.markdown b/website/docs/r/network_services_service_lb_policies.html.markdown new file mode 100644 index 00000000000..920634ff9b4 --- /dev/null +++ b/website/docs/r/network_services_service_lb_policies.html.markdown @@ -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. + + +
+## 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" +} +``` + +## 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. + + +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. + +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).