Skip to content

Commit 07599f1

Browse files
modular-magicianEdward Sun
and
Edward Sun
authored
fix sending disableConnectionDrainOnFailover (#7326) (#13897)
* fix sending disableConnectionDrainOnFailover * add a test * update tests --------- Signed-off-by: Modular Magician <magic-modules@google.com> Co-authored-by: Edward Sun <sunedward@google.com>
1 parent 649ff9b commit 07599f1

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.changelog/7326.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed the error of invalid value for field `resource.failoverPolicy` when UDP is selected on `google_compute_region_backend_service`
3+
```

google/resource_compute_region_backend_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ Defaults to 1024.`,
490490
Schema: map[string]*schema.Schema{
491491
"disable_connection_drain_on_failover": {
492492
Type: schema.TypeBool,
493+
Computed: true,
493494
Optional: true,
494495
Description: `On failover or failback, this field indicates whether connection drain
495496
will be honored. Setting this to true has the following effect: connections
@@ -503,6 +504,7 @@ The default is false.`,
503504
},
504505
"drop_traffic_if_unhealthy": {
505506
Type: schema.TypeBool,
507+
Computed: true,
506508
Optional: true,
507509
Description: `This option is used only when no healthy VMs are detected in the primary
508510
and backup instance groups. When set to true, traffic is dropped. When
@@ -3238,7 +3240,7 @@ func expandComputeRegionBackendServiceFailoverPolicy(v interface{}, d TerraformR
32383240
transformedDisableConnectionDrainOnFailover, err := expandComputeRegionBackendServiceFailoverPolicyDisableConnectionDrainOnFailover(original["disable_connection_drain_on_failover"], d, config)
32393241
if err != nil {
32403242
return nil, err
3241-
} else {
3243+
} else if val := reflect.ValueOf(transformedDisableConnectionDrainOnFailover); val.IsValid() && !isEmptyValue(val) {
32423244
transformed["disableConnectionDrainOnFailover"] = transformedDisableConnectionDrainOnFailover
32433245
}
32443246

google/resource_compute_region_backend_service_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,45 @@ func TestAccComputeRegionBackendService_withBackendAndIAP(t *testing.T) {
222222
})
223223
}
224224

225+
func TestAccComputeRegionBackendService_UDPFailOverPolicyUpdate(t *testing.T) {
226+
t.Parallel()
227+
228+
serviceName := fmt.Sprintf("tf-test-%s", randString(t, 10))
229+
checkName := fmt.Sprintf("tf-test-%s", randString(t, 10))
230+
231+
vcrTest(t, resource.TestCase{
232+
PreCheck: func() { testAccPreCheck(t) },
233+
Providers: testAccProviders,
234+
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
235+
Steps: []resource.TestStep{
236+
{
237+
Config: testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, "TCP", "true", checkName),
238+
},
239+
{
240+
ResourceName: "google_compute_region_backend_service.foobar",
241+
ImportState: true,
242+
ImportStateVerify: true,
243+
},
244+
{
245+
Config: testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, "TCP", "false", checkName),
246+
},
247+
{
248+
ResourceName: "google_compute_region_backend_service.foobar",
249+
ImportState: true,
250+
ImportStateVerify: true,
251+
},
252+
{
253+
Config: testAccComputeRegionBackendService_UDPFailOverPolicy(serviceName, "UDP", "false", checkName),
254+
},
255+
{
256+
ResourceName: "google_compute_region_backend_service.foobar",
257+
ImportState: true,
258+
ImportStateVerify: true,
259+
},
260+
},
261+
})
262+
}
263+
225264
func testAccComputeRegionBackendService_ilbBasic(serviceName, checkName string) string {
226265
return fmt.Sprintf(`
227266
resource "google_compute_region_backend_service" "foobar" {
@@ -283,6 +322,59 @@ resource "google_compute_health_check" "health_check" {
283322
`, serviceName, checkName)
284323
}
285324

325+
func testAccComputeRegionBackendService_UDPFailOverPolicy(serviceName, protocol, failover, checkName string) string {
326+
return fmt.Sprintf(`
327+
resource "google_compute_region_backend_service" "foobar" {
328+
name = "%s"
329+
health_checks = [google_compute_health_check.zero.self_link]
330+
region = "us-central1"
331+
332+
protocol = "%s"
333+
failover_policy {
334+
# Disable connection drain on failover cannot be set when the protocol is UDP
335+
drop_traffic_if_unhealthy = "%s"
336+
}
337+
}
338+
339+
resource "google_compute_health_check" "zero" {
340+
name = "%s"
341+
check_interval_sec = 1
342+
timeout_sec = 1
343+
344+
tcp_health_check {
345+
port = "80"
346+
}
347+
}
348+
`, serviceName, protocol, failover, checkName)
349+
}
350+
351+
func testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, protocol, failover, checkName string) string {
352+
return fmt.Sprintf(`
353+
resource "google_compute_region_backend_service" "foobar" {
354+
name = "%s"
355+
health_checks = [google_compute_health_check.zero.self_link]
356+
region = "us-central1"
357+
358+
protocol = "%s"
359+
failover_policy {
360+
# Disable connection drain on failover cannot be set when the protocol is UDP
361+
drop_traffic_if_unhealthy = "%s"
362+
disable_connection_drain_on_failover = "%s"
363+
}
364+
}
365+
366+
resource "google_compute_health_check" "zero" {
367+
name = "%s"
368+
check_interval_sec = 1
369+
timeout_sec = 1
370+
371+
tcp_health_check {
372+
port = "80"
373+
}
374+
}
375+
`, serviceName, protocol, failover, failover, checkName)
376+
}
377+
286378
func testAccComputeRegionBackendService_basic(serviceName, checkName string) string {
287379
return fmt.Sprintf(`
288380
resource "google_compute_region_backend_service" "foobar" {

0 commit comments

Comments
 (0)