diff --git a/.changelog/11957.txt b/.changelog/11957.txt new file mode 100644 index 00000000000..690b84555a3 --- /dev/null +++ b/.changelog/11957.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added `ipAddressSelectionPolicy` field to `google_compute_backend_service` and `google_compute_region_backend_service`. +``` \ No newline at end of file diff --git a/google/services/compute/resource_compute_backend_service.go b/google/services/compute/resource_compute_backend_service.go index 4d6469cfa7a..51ac9a7d1be 100644 --- a/google/services/compute/resource_compute_backend_service.go +++ b/google/services/compute/resource_compute_backend_service.go @@ -663,6 +663,12 @@ For internal load balancing, a URL to a HealthCheck resource must be specified i }, }, }, + "ip_address_selection_policy": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidateEnum([]string{"IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY", ""}), + Description: `Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC). Possible values: ["IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY"]`, + }, "load_balancing_scheme": { Type: schema.TypeString, Optional: true, @@ -1416,6 +1422,12 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{ } else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) { obj["iap"] = iapProp } + ipAddressSelectionPolicyProp, err := expandComputeBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipAddressSelectionPolicyProp)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) { + obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp + } loadBalancingSchemeProp, err := expandComputeBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config) if err != nil { return err @@ -1721,6 +1733,9 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{}) if err := d.Set("iap", flattenComputeBackendServiceIap(res["iap"], d, config)); err != nil { return fmt.Errorf("Error reading BackendService: %s", err) } + if err := d.Set("ip_address_selection_policy", flattenComputeBackendServiceIpAddressSelectionPolicy(res["ipAddressSelectionPolicy"], d, config)); err != nil { + return fmt.Errorf("Error reading BackendService: %s", err) + } if err := d.Set("load_balancing_scheme", flattenComputeBackendServiceLoadBalancingScheme(res["loadBalancingScheme"], d, config)); err != nil { return fmt.Errorf("Error reading BackendService: %s", err) } @@ -1873,6 +1888,12 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{ } else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) { obj["iap"] = iapProp } + ipAddressSelectionPolicyProp, err := expandComputeBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) { + obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp + } loadBalancingSchemeProp, err := expandComputeBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config) if err != nil { return err @@ -2867,6 +2888,10 @@ func flattenComputeBackendServiceIapOauth2ClientSecretSha256(v interface{}, d *s return v } +func flattenComputeBackendServiceIpAddressSelectionPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenComputeBackendServiceLoadBalancingScheme(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -4114,6 +4139,10 @@ func expandComputeBackendServiceIapOauth2ClientSecretSha256(v interface{}, d tpg return v, nil } +func expandComputeBackendServiceIpAddressSelectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandComputeBackendServiceLoadBalancingScheme(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/google/services/compute/resource_compute_backend_service_generated_test.go b/google/services/compute/resource_compute_backend_service_generated_test.go index 296547e2484..a29a0987708 100644 --- a/google/services/compute/resource_compute_backend_service_generated_test.go +++ b/google/services/compute/resource_compute_backend_service_generated_test.go @@ -395,6 +395,41 @@ resource "google_compute_health_check" "default" { `, context) } +func TestAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(context), + }, + { + ResourceName: "google_compute_backend_service.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "security_settings.0.aws_v4_authentication.0.access_key"}, + }, + }, + }) +} + +func testAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_backend_service" "default" { + name = "tf-test-backend-service%{random_suffix}" + load_balancing_scheme = "EXTERNAL_MANAGED" + ip_address_selection_policy = "IPV6_ONLY" +} +`, context) +} + func testAccCheckComputeBackendServiceDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/google/services/compute/resource_compute_region_backend_service.go b/google/services/compute/resource_compute_region_backend_service.go index 0ef07785afa..cbd2b3e76ef 100644 --- a/google/services/compute/resource_compute_region_backend_service.go +++ b/google/services/compute/resource_compute_region_backend_service.go @@ -590,6 +590,12 @@ or serverless NEG as a backend.`, }, }, }, + "ip_address_selection_policy": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.ValidateEnum([]string{"IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY", ""}), + Description: `Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC). Possible values: ["IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY"]`, + }, "load_balancing_scheme": { Type: schema.TypeString, Optional: true, @@ -1182,6 +1188,12 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) { obj["iap"] = iapProp } + ipAddressSelectionPolicyProp, err := expandComputeRegionBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipAddressSelectionPolicyProp)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) { + obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp + } loadBalancingSchemeProp, err := expandComputeRegionBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config) if err != nil { return err @@ -1424,6 +1436,9 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf if err := d.Set("iap", flattenComputeRegionBackendServiceIap(res["iap"], d, config)); err != nil { return fmt.Errorf("Error reading RegionBackendService: %s", err) } + if err := d.Set("ip_address_selection_policy", flattenComputeRegionBackendServiceIpAddressSelectionPolicy(res["ipAddressSelectionPolicy"], d, config)); err != nil { + return fmt.Errorf("Error reading RegionBackendService: %s", err) + } if err := d.Set("load_balancing_scheme", flattenComputeRegionBackendServiceLoadBalancingScheme(res["loadBalancingScheme"], d, config)); err != nil { return fmt.Errorf("Error reading RegionBackendService: %s", err) } @@ -1555,6 +1570,12 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) { obj["iap"] = iapProp } + ipAddressSelectionPolicyProp, err := expandComputeRegionBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) { + obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp + } loadBalancingSchemeProp, err := expandComputeRegionBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config) if err != nil { return err @@ -2462,6 +2483,10 @@ func flattenComputeRegionBackendServiceIapOauth2ClientSecretSha256(v interface{} return v } +func flattenComputeRegionBackendServiceIpAddressSelectionPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenComputeRegionBackendServiceLoadBalancingScheme(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -3576,6 +3601,10 @@ func expandComputeRegionBackendServiceIapOauth2ClientSecretSha256(v interface{}, return v, nil } +func expandComputeRegionBackendServiceIpAddressSelectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandComputeRegionBackendServiceLoadBalancingScheme(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/google/services/compute/resource_compute_region_backend_service_generated_test.go b/google/services/compute/resource_compute_region_backend_service_generated_test.go index 782ca65ea14..db67e28a74d 100644 --- a/google/services/compute/resource_compute_region_backend_service_generated_test.go +++ b/google/services/compute/resource_compute_region_backend_service_generated_test.go @@ -372,6 +372,54 @@ resource "google_compute_subnetwork" "default" { `, context) } +func TestAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(context), + }, + { + ResourceName: "google_compute_region_backend_service.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "network", "region"}, + }, + }, + }) +} + +func testAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_region_backend_service" "default" { + name = "tf-test-region-service%{random_suffix}" + region = "us-central1" + health_checks = [google_compute_region_health_check.health_check.id] + + load_balancing_scheme = "EXTERNAL_MANAGED" + protocol = "HTTP" + ip_address_selection_policy = "IPV6_ONLY" +} + +resource "google_compute_region_health_check" "health_check" { + name = "tf-test-rbs-health-check%{random_suffix}" + region = "us-central1" + + tcp_health_check { + port = 80 + } +} +`, context) +} + func testAccCheckComputeRegionBackendServiceDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index 6a4c84a9b61..7edeae294bf 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -395,6 +395,21 @@ resource "google_compute_health_check" "default" { } } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Backend Service Ip Address Selection Policy + + +```hcl +resource "google_compute_backend_service" "default" { + name = "backend-service" + load_balancing_scheme = "EXTERNAL_MANAGED" + ip_address_selection_policy = "IPV6_ONLY" +} +``` ## Argument Reference @@ -493,6 +508,11 @@ The following arguments are supported: Settings for enabling Cloud Identity Aware Proxy Structure is [documented below](#nested_iap). +* `ip_address_selection_policy` - + (Optional) + Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC). + Possible values are: `IPV4_ONLY`, `PREFER_IPV6`, `IPV6_ONLY`. + * `load_balancing_scheme` - (Optional) Indicates whether the backend service will be used with internal or diff --git a/website/docs/r/compute_region_backend_service.html.markdown b/website/docs/r/compute_region_backend_service.html.markdown index cf0647b06fa..72d32914af5 100644 --- a/website/docs/r/compute_region_backend_service.html.markdown +++ b/website/docs/r/compute_region_backend_service.html.markdown @@ -398,6 +398,34 @@ resource "google_compute_region_health_check" "health_check" { } } ``` +
+ + Open in Cloud Shell + +
+## Example Usage - Region Backend Service Ip Address Selection Policy + + +```hcl +resource "google_compute_region_backend_service" "default" { + name = "region-service" + region = "us-central1" + health_checks = [google_compute_region_health_check.health_check.id] + + load_balancing_scheme = "EXTERNAL_MANAGED" + protocol = "HTTP" + ip_address_selection_policy = "IPV6_ONLY" +} + +resource "google_compute_region_health_check" "health_check" { + name = "rbs-health-check" + region = "us-central1" + + tcp_health_check { + port = 80 + } +} +``` ## Argument Reference @@ -488,6 +516,11 @@ The following arguments are supported: Settings for enabling Cloud Identity Aware Proxy Structure is [documented below](#nested_iap). +* `ip_address_selection_policy` - + (Optional) + Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC). + Possible values are: `IPV4_ONLY`, `PREFER_IPV6`, `IPV6_ONLY`. + * `load_balancing_scheme` - (Optional) Indicates what kind of load balancing this regional backend service