Skip to content

Commit

Permalink
Fix update when changing health check type (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo authored Jan 12, 2018
1 parent a3e2c3e commit 3d178f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions google/resource_compute_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
hchk := &compute.HealthCheck{
Name: d.Get("name").(string),
}

nullFields := make([]string, 0, 3)

// Optional things
if v, ok := d.GetOk("description"); ok {
hchk.Description = v.(string)
Expand Down Expand Up @@ -355,6 +358,8 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
tcpHealthCheck.Response = val.(string)
}
hchk.TcpHealthCheck = tcpHealthCheck
} else {
nullFields = append(nullFields, "TcpHealthCheck")
}
if v, ok := d.GetOk("ssl_health_check"); ok {
hchk.Type = "SSL"
Expand All @@ -373,6 +378,8 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
sslHealthCheck.Response = val.(string)
}
hchk.SslHealthCheck = sslHealthCheck
} else {
nullFields = append(nullFields, "SslHealthCheck")
}
if v, ok := d.GetOk("http_health_check"); ok {
hchk.Type = "HTTP"
Expand All @@ -391,6 +398,8 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
httpHealthCheck.RequestPath = val.(string)
}
hchk.HttpHealthCheck = httpHealthCheck
} else {
nullFields = append(nullFields, "HttpHealthCheck")
}

if v, ok := d.GetOk("https_health_check"); ok {
Expand All @@ -410,8 +419,12 @@ func resourceComputeHealthCheckUpdate(d *schema.ResourceData, meta interface{})
httpsHealthCheck.RequestPath = val.(string)
}
hchk.HttpsHealthCheck = httpsHealthCheck
} else {
nullFields = append(nullFields, "HttpsHealthCheck")
}

hchk.NullFields = nullFields

log.Printf("[DEBUG] HealthCheck patch request: %#v", hchk)
op, err := config.clientCompute.HealthChecks.Patch(
project, hchk.Name, hchk).Do()
Expand Down
29 changes: 29 additions & 0 deletions google/resource_compute_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ func TestAccComputeHealthCheck_https(t *testing.T) {
})
}

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

hckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeHealthCheck_https(hckName),
},
resource.TestStep{
Config: testAccComputeHealthCheck_http(hckName),
},
resource.TestStep{
Config: testAccComputeHealthCheck_ssl(hckName),
},
resource.TestStep{
Config: testAccComputeHealthCheck_tcp(hckName),
},
resource.TestStep{
Config: testAccComputeHealthCheck_https(hckName),
},
},
})
}

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

Expand Down

0 comments on commit 3d178f5

Please sign in to comment.