Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update when changing health check type #944

Merged
merged 1 commit into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the problem was that it wasn't possible to switch types, and this confirms that the type changes work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

},
},
})
}

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

Expand Down