Skip to content

Commit

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

* add a test

* update tests

---------

Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
2 people authored and mdtro committed Mar 2, 2023
1 parent 9ef5e3a commit 7da2579
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mmv1/products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,10 @@ overrides: !ruby/object:Overrides::ResourceOverrides
logConfig.enable: !ruby/object:Overrides::Terraform::PropertyOverride
send_empty_value: true
failoverPolicy.disableConnectionDrainOnFailover: !ruby/object:Overrides::Terraform::PropertyOverride
send_empty_value: true
default_from_api: true
failoverPolicy.dropTrafficIfUnhealthy: !ruby/object:Overrides::Terraform::PropertyOverride
send_empty_value: true
default_from_api: true
connectionTrackingPolicy.idleTimeoutSec: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
RegionInstanceGroupManager: !ruby/object:Overrides::Terraform::ResourceOverride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,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,
},
},
})
}

<% unless version == 'ga' -%>
func TestAccComputeRegionBackendService_subsettingUpdate(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -501,6 +540,60 @@ resource "google_compute_health_check" "health_check" {
}
<% end -%>

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 7da2579

Please sign in to comment.