Skip to content

Commit

Permalink
fix sending disableConnectionDrainOnFailover (#7326) (#13897)
Browse files Browse the repository at this point in the history
* fix sending disableConnectionDrainOnFailover

* add a test

* update tests

---------

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Mar 2, 2023
1 parent 649ff9b commit 07599f1
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/7326.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed the error of invalid value for field `resource.failoverPolicy` when UDP is selected on `google_compute_region_backend_service`
```
4 changes: 3 additions & 1 deletion google/resource_compute_region_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ Defaults to 1024.`,
Schema: map[string]*schema.Schema{
"disable_connection_drain_on_failover": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: `On failover or failback, this field indicates whether connection drain
will be honored. Setting this to true has the following effect: connections
Expand All @@ -503,6 +504,7 @@ The default is false.`,
},
"drop_traffic_if_unhealthy": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: `This option is used only when no healthy VMs are detected in the primary
and backup instance groups. When set to true, traffic is dropped. When
Expand Down Expand Up @@ -3238,7 +3240,7 @@ func expandComputeRegionBackendServiceFailoverPolicy(v interface{}, d TerraformR
transformedDisableConnectionDrainOnFailover, err := expandComputeRegionBackendServiceFailoverPolicyDisableConnectionDrainOnFailover(original["disable_connection_drain_on_failover"], d, config)
if err != nil {
return nil, err
} else {
} else if val := reflect.ValueOf(transformedDisableConnectionDrainOnFailover); val.IsValid() && !isEmptyValue(val) {
transformed["disableConnectionDrainOnFailover"] = transformedDisableConnectionDrainOnFailover
}

Expand Down
92 changes: 92 additions & 0 deletions google/resource_compute_region_backend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,45 @@ func TestAccComputeRegionBackendService_withBackendAndIAP(t *testing.T) {
})
}

func TestAccComputeRegionBackendService_UDPFailOverPolicyUpdate(t *testing.T) {
t.Parallel()

serviceName := fmt.Sprintf("tf-test-%s", randString(t, 10))
checkName := fmt.Sprintf("tf-test-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, "TCP", "true", checkName),
},
{
ResourceName: "google_compute_region_backend_service.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, "TCP", "false", checkName),
},
{
ResourceName: "google_compute_region_backend_service.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRegionBackendService_UDPFailOverPolicy(serviceName, "UDP", "false", checkName),
},
{
ResourceName: "google_compute_region_backend_service.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeRegionBackendService_ilbBasic(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
Expand Down Expand Up @@ -283,6 +322,59 @@ resource "google_compute_health_check" "health_check" {
`, serviceName, checkName)
}

func testAccComputeRegionBackendService_UDPFailOverPolicy(serviceName, protocol, failover, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
name = "%s"
health_checks = [google_compute_health_check.zero.self_link]
region = "us-central1"
protocol = "%s"
failover_policy {
# Disable connection drain on failover cannot be set when the protocol is UDP
drop_traffic_if_unhealthy = "%s"
}
}
resource "google_compute_health_check" "zero" {
name = "%s"
check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, serviceName, protocol, failover, checkName)
}

func testAccComputeRegionBackendService_UDPFailOverPolicyHasDrain(serviceName, protocol, failover, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
name = "%s"
health_checks = [google_compute_health_check.zero.self_link]
region = "us-central1"
protocol = "%s"
failover_policy {
# Disable connection drain on failover cannot be set when the protocol is UDP
drop_traffic_if_unhealthy = "%s"
disable_connection_drain_on_failover = "%s"
}
}
resource "google_compute_health_check" "zero" {
name = "%s"
check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
`, serviceName, protocol, failover, failover, checkName)
}

func testAccComputeRegionBackendService_basic(serviceName, checkName string) string {
return fmt.Sprintf(`
resource "google_compute_region_backend_service" "foobar" {
Expand Down

0 comments on commit 07599f1

Please sign in to comment.