Skip to content

Commit 824d665

Browse files
Ip address selection policy (#11957) (#19863)
[upstream:4c84dbe59bdde7f2e6a485ac0339ebd0772c9ed0] Signed-off-by: Modular Magician <[email protected]>
1 parent 158cc59 commit 824d665

7 files changed

+197
-0
lines changed

.changelog/11957.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `ipAddressSelectionPolicy` field to `google_compute_backend_service` and `google_compute_region_backend_service`.
3+
```

google/services/compute/resource_compute_backend_service.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,12 @@ For internal load balancing, a URL to a HealthCheck resource must be specified i
663663
},
664664
},
665665
},
666+
"ip_address_selection_policy": {
667+
Type: schema.TypeString,
668+
Optional: true,
669+
ValidateFunc: verify.ValidateEnum([]string{"IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY", ""}),
670+
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"]`,
671+
},
666672
"load_balancing_scheme": {
667673
Type: schema.TypeString,
668674
Optional: true,
@@ -1416,6 +1422,12 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{
14161422
} else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) {
14171423
obj["iap"] = iapProp
14181424
}
1425+
ipAddressSelectionPolicyProp, err := expandComputeBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config)
1426+
if err != nil {
1427+
return err
1428+
} else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipAddressSelectionPolicyProp)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) {
1429+
obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp
1430+
}
14191431
loadBalancingSchemeProp, err := expandComputeBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config)
14201432
if err != nil {
14211433
return err
@@ -1721,6 +1733,9 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
17211733
if err := d.Set("iap", flattenComputeBackendServiceIap(res["iap"], d, config)); err != nil {
17221734
return fmt.Errorf("Error reading BackendService: %s", err)
17231735
}
1736+
if err := d.Set("ip_address_selection_policy", flattenComputeBackendServiceIpAddressSelectionPolicy(res["ipAddressSelectionPolicy"], d, config)); err != nil {
1737+
return fmt.Errorf("Error reading BackendService: %s", err)
1738+
}
17241739
if err := d.Set("load_balancing_scheme", flattenComputeBackendServiceLoadBalancingScheme(res["loadBalancingScheme"], d, config)); err != nil {
17251740
return fmt.Errorf("Error reading BackendService: %s", err)
17261741
}
@@ -1873,6 +1888,12 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{
18731888
} else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) {
18741889
obj["iap"] = iapProp
18751890
}
1891+
ipAddressSelectionPolicyProp, err := expandComputeBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config)
1892+
if err != nil {
1893+
return err
1894+
} else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) {
1895+
obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp
1896+
}
18761897
loadBalancingSchemeProp, err := expandComputeBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config)
18771898
if err != nil {
18781899
return err
@@ -2867,6 +2888,10 @@ func flattenComputeBackendServiceIapOauth2ClientSecretSha256(v interface{}, d *s
28672888
return v
28682889
}
28692890

2891+
func flattenComputeBackendServiceIpAddressSelectionPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2892+
return v
2893+
}
2894+
28702895
func flattenComputeBackendServiceLoadBalancingScheme(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
28712896
return v
28722897
}
@@ -4114,6 +4139,10 @@ func expandComputeBackendServiceIapOauth2ClientSecretSha256(v interface{}, d tpg
41144139
return v, nil
41154140
}
41164141

4142+
func expandComputeBackendServiceIpAddressSelectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
4143+
return v, nil
4144+
}
4145+
41174146
func expandComputeBackendServiceLoadBalancingScheme(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
41184147
return v, nil
41194148
}

google/services/compute/resource_compute_backend_service_generated_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,41 @@ resource "google_compute_health_check" "default" {
395395
`, context)
396396
}
397397

398+
func TestAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(t *testing.T) {
399+
t.Parallel()
400+
401+
context := map[string]interface{}{
402+
"random_suffix": acctest.RandString(t, 10),
403+
}
404+
405+
acctest.VcrTest(t, resource.TestCase{
406+
PreCheck: func() { acctest.AccTestPreCheck(t) },
407+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
408+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
409+
Steps: []resource.TestStep{
410+
{
411+
Config: testAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(context),
412+
},
413+
{
414+
ResourceName: "google_compute_backend_service.default",
415+
ImportState: true,
416+
ImportStateVerify: true,
417+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "security_settings.0.aws_v4_authentication.0.access_key"},
418+
},
419+
},
420+
})
421+
}
422+
423+
func testAccComputeBackendService_backendServiceIpAddressSelectionPolicyExample(context map[string]interface{}) string {
424+
return acctest.Nprintf(`
425+
resource "google_compute_backend_service" "default" {
426+
name = "tf-test-backend-service%{random_suffix}"
427+
load_balancing_scheme = "EXTERNAL_MANAGED"
428+
ip_address_selection_policy = "IPV6_ONLY"
429+
}
430+
`, context)
431+
}
432+
398433
func testAccCheckComputeBackendServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
399434
return func(s *terraform.State) error {
400435
for name, rs := range s.RootModule().Resources {

google/services/compute/resource_compute_region_backend_service.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ or serverless NEG as a backend.`,
590590
},
591591
},
592592
},
593+
"ip_address_selection_policy": {
594+
Type: schema.TypeString,
595+
Optional: true,
596+
ValidateFunc: verify.ValidateEnum([]string{"IPV4_ONLY", "PREFER_IPV6", "IPV6_ONLY", ""}),
597+
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"]`,
598+
},
593599
"load_balancing_scheme": {
594600
Type: schema.TypeString,
595601
Optional: true,
@@ -1182,6 +1188,12 @@ func resourceComputeRegionBackendServiceCreate(d *schema.ResourceData, meta inte
11821188
} else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) {
11831189
obj["iap"] = iapProp
11841190
}
1191+
ipAddressSelectionPolicyProp, err := expandComputeRegionBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config)
1192+
if err != nil {
1193+
return err
1194+
} else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipAddressSelectionPolicyProp)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) {
1195+
obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp
1196+
}
11851197
loadBalancingSchemeProp, err := expandComputeRegionBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config)
11861198
if err != nil {
11871199
return err
@@ -1424,6 +1436,9 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
14241436
if err := d.Set("iap", flattenComputeRegionBackendServiceIap(res["iap"], d, config)); err != nil {
14251437
return fmt.Errorf("Error reading RegionBackendService: %s", err)
14261438
}
1439+
if err := d.Set("ip_address_selection_policy", flattenComputeRegionBackendServiceIpAddressSelectionPolicy(res["ipAddressSelectionPolicy"], d, config)); err != nil {
1440+
return fmt.Errorf("Error reading RegionBackendService: %s", err)
1441+
}
14271442
if err := d.Set("load_balancing_scheme", flattenComputeRegionBackendServiceLoadBalancingScheme(res["loadBalancingScheme"], d, config)); err != nil {
14281443
return fmt.Errorf("Error reading RegionBackendService: %s", err)
14291444
}
@@ -1555,6 +1570,12 @@ func resourceComputeRegionBackendServiceUpdate(d *schema.ResourceData, meta inte
15551570
} else if v, ok := d.GetOkExists("iap"); ok || !reflect.DeepEqual(v, iapProp) {
15561571
obj["iap"] = iapProp
15571572
}
1573+
ipAddressSelectionPolicyProp, err := expandComputeRegionBackendServiceIpAddressSelectionPolicy(d.Get("ip_address_selection_policy"), d, config)
1574+
if err != nil {
1575+
return err
1576+
} else if v, ok := d.GetOkExists("ip_address_selection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipAddressSelectionPolicyProp)) {
1577+
obj["ipAddressSelectionPolicy"] = ipAddressSelectionPolicyProp
1578+
}
15581579
loadBalancingSchemeProp, err := expandComputeRegionBackendServiceLoadBalancingScheme(d.Get("load_balancing_scheme"), d, config)
15591580
if err != nil {
15601581
return err
@@ -2462,6 +2483,10 @@ func flattenComputeRegionBackendServiceIapOauth2ClientSecretSha256(v interface{}
24622483
return v
24632484
}
24642485

2486+
func flattenComputeRegionBackendServiceIpAddressSelectionPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2487+
return v
2488+
}
2489+
24652490
func flattenComputeRegionBackendServiceLoadBalancingScheme(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
24662491
return v
24672492
}
@@ -3576,6 +3601,10 @@ func expandComputeRegionBackendServiceIapOauth2ClientSecretSha256(v interface{},
35763601
return v, nil
35773602
}
35783603

3604+
func expandComputeRegionBackendServiceIpAddressSelectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
3605+
return v, nil
3606+
}
3607+
35793608
func expandComputeRegionBackendServiceLoadBalancingScheme(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
35803609
return v, nil
35813610
}

google/services/compute/resource_compute_region_backend_service_generated_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,54 @@ resource "google_compute_subnetwork" "default" {
372372
`, context)
373373
}
374374

375+
func TestAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(t *testing.T) {
376+
t.Parallel()
377+
378+
context := map[string]interface{}{
379+
"random_suffix": acctest.RandString(t, 10),
380+
}
381+
382+
acctest.VcrTest(t, resource.TestCase{
383+
PreCheck: func() { acctest.AccTestPreCheck(t) },
384+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
385+
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
386+
Steps: []resource.TestStep{
387+
{
388+
Config: testAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(context),
389+
},
390+
{
391+
ResourceName: "google_compute_region_backend_service.default",
392+
ImportState: true,
393+
ImportStateVerify: true,
394+
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret", "network", "region"},
395+
},
396+
},
397+
})
398+
}
399+
400+
func testAccComputeRegionBackendService_regionBackendServiceIpAddressSelectionPolicyExample(context map[string]interface{}) string {
401+
return acctest.Nprintf(`
402+
resource "google_compute_region_backend_service" "default" {
403+
name = "tf-test-region-service%{random_suffix}"
404+
region = "us-central1"
405+
health_checks = [google_compute_region_health_check.health_check.id]
406+
407+
load_balancing_scheme = "EXTERNAL_MANAGED"
408+
protocol = "HTTP"
409+
ip_address_selection_policy = "IPV6_ONLY"
410+
}
411+
412+
resource "google_compute_region_health_check" "health_check" {
413+
name = "tf-test-rbs-health-check%{random_suffix}"
414+
region = "us-central1"
415+
416+
tcp_health_check {
417+
port = 80
418+
}
419+
}
420+
`, context)
421+
}
422+
375423
func testAccCheckComputeRegionBackendServiceDestroyProducer(t *testing.T) func(s *terraform.State) error {
376424
return func(s *terraform.State) error {
377425
for name, rs := range s.RootModule().Resources {

website/docs/r/compute_backend_service.html.markdown

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,21 @@ resource "google_compute_health_check" "default" {
395395
}
396396
}
397397
```
398+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
399+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=backend_service_ip_address_selection_policy&open_in_editor=main.tf" target="_blank">
400+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
401+
</a>
402+
</div>
403+
## Example Usage - Backend Service Ip Address Selection Policy
404+
405+
406+
```hcl
407+
resource "google_compute_backend_service" "default" {
408+
name = "backend-service"
409+
load_balancing_scheme = "EXTERNAL_MANAGED"
410+
ip_address_selection_policy = "IPV6_ONLY"
411+
}
412+
```
398413

399414
## Argument Reference
400415

@@ -493,6 +508,11 @@ The following arguments are supported:
493508
Settings for enabling Cloud Identity Aware Proxy
494509
Structure is [documented below](#nested_iap).
495510

511+
* `ip_address_selection_policy` -
512+
(Optional)
513+
Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC).
514+
Possible values are: `IPV4_ONLY`, `PREFER_IPV6`, `IPV6_ONLY`.
515+
496516
* `load_balancing_scheme` -
497517
(Optional)
498518
Indicates whether the backend service will be used with internal or

website/docs/r/compute_region_backend_service.html.markdown

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,34 @@ resource "google_compute_region_health_check" "health_check" {
398398
}
399399
}
400400
```
401+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
402+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=region_backend_service_ip_address_selection_policy&open_in_editor=main.tf" target="_blank">
403+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
404+
</a>
405+
</div>
406+
## Example Usage - Region Backend Service Ip Address Selection Policy
407+
408+
409+
```hcl
410+
resource "google_compute_region_backend_service" "default" {
411+
name = "region-service"
412+
region = "us-central1"
413+
health_checks = [google_compute_region_health_check.health_check.id]
414+
415+
load_balancing_scheme = "EXTERNAL_MANAGED"
416+
protocol = "HTTP"
417+
ip_address_selection_policy = "IPV6_ONLY"
418+
}
419+
420+
resource "google_compute_region_health_check" "health_check" {
421+
name = "rbs-health-check"
422+
region = "us-central1"
423+
424+
tcp_health_check {
425+
port = 80
426+
}
427+
}
428+
```
401429

402430
## Argument Reference
403431

@@ -488,6 +516,11 @@ The following arguments are supported:
488516
Settings for enabling Cloud Identity Aware Proxy
489517
Structure is [documented below](#nested_iap).
490518

519+
* `ip_address_selection_policy` -
520+
(Optional)
521+
Specifies preference of traffic to the backend (from the proxy and from the client for proxyless gRPC).
522+
Possible values are: `IPV4_ONLY`, `PREFER_IPV6`, `IPV6_ONLY`.
523+
491524
* `load_balancing_scheme` -
492525
(Optional)
493526
Indicates what kind of load balancing this regional backend service

0 commit comments

Comments
 (0)