Merge pull request #951 from sparkprime/fix_health_check

Fix a number of healthcheck bugs
This commit is contained in:
Paul Hinze 2015-02-09 18:50:14 -06:00
commit e81c995301
2 changed files with 54 additions and 35 deletions

View File

@ -21,25 +21,23 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
"check_interval_sec": &schema.Schema{ "check_interval_sec": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
"description": &schema.Schema{ "description": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: false,
}, },
"healthy_threshold": &schema.Schema{ "healthy_threshold": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
"host": &schema.Schema{ "host": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: false,
}, },
"name": &schema.Schema{ "name": &schema.Schema{
@ -51,13 +49,13 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
"request_path": &schema.Schema{ "request_path": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
"self_link": &schema.Schema{ "self_link": &schema.Schema{
@ -68,13 +66,13 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
"timeout_sec": &schema.Schema{ "timeout_sec": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
"unhealthy_threshold": &schema.Schema{ "unhealthy_threshold": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: false, Computed: true,
}, },
}, },
} }
@ -85,25 +83,32 @@ func resourceComputeHttpHealthCheckCreate(d *schema.ResourceData, meta interface
// Build the parameter // Build the parameter
hchk := &compute.HttpHealthCheck{ hchk := &compute.HttpHealthCheck{
Description: d.Get("description").(string),
Host: d.Get("host").(string),
Name: d.Get("name").(string), Name: d.Get("name").(string),
RequestPath: d.Get("request_path").(string),
} }
if d.Get("check_interval_sec") != nil { // Optional things
hchk.CheckIntervalSec = int64(d.Get("check_interval_sec").(int)) if v, ok := d.GetOk("description"); ok {
hchk.Description = v.(string)
} }
if d.Get("health_threshold") != nil { if v, ok := d.GetOk("host"); ok {
hchk.HealthyThreshold = int64(d.Get("healthy_threshold").(int)) hchk.Host = v.(string)
} }
if d.Get("port") != nil { if v, ok := d.GetOk("request_path"); ok {
hchk.Port = int64(d.Get("port").(int)) hchk.RequestPath = v.(string)
} }
if d.Get("timeout") != nil { if v, ok := d.GetOk("check_interval_sec"); ok {
hchk.TimeoutSec = int64(d.Get("timeout_sec").(int)) hchk.CheckIntervalSec = int64(v.(int))
} }
if d.Get("unhealthy_threshold") != nil { if v, ok := d.GetOk("health_threshold"); ok {
hchk.UnhealthyThreshold = int64(d.Get("unhealthy_threshold").(int)) hchk.HealthyThreshold = int64(v.(int))
}
if v, ok := d.GetOk("port"); ok {
hchk.Port = int64(v.(int))
}
if v, ok := d.GetOk("timeout_sec"); ok {
hchk.TimeoutSec = int64(v.(int))
}
if v, ok := d.GetOk("unhealthy_threshold"); ok {
hchk.UnhealthyThreshold = int64(v.(int))
} }
log.Printf("[DEBUG] HttpHealthCheck insert request: %#v", hchk) log.Printf("[DEBUG] HttpHealthCheck insert request: %#v", hchk)
@ -147,25 +152,32 @@ func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface
// Build the parameter // Build the parameter
hchk := &compute.HttpHealthCheck{ hchk := &compute.HttpHealthCheck{
Description: d.Get("description").(string),
Host: d.Get("host").(string),
Name: d.Get("name").(string), Name: d.Get("name").(string),
RequestPath: d.Get("request_path").(string),
} }
if d.Get("check_interval_sec") != nil { // Optional things
hchk.CheckIntervalSec = int64(d.Get("check_interval_sec").(int)) if v, ok := d.GetOk("description"); ok {
hchk.Description = v.(string)
} }
if d.Get("health_threshold") != nil { if v, ok := d.GetOk("host"); ok {
hchk.HealthyThreshold = int64(d.Get("healthy_threshold").(int)) hchk.Host = v.(string)
} }
if d.Get("port") != nil { if v, ok := d.GetOk("request_path"); ok {
hchk.Port = int64(d.Get("port").(int)) hchk.RequestPath = v.(string)
} }
if d.Get("timeout") != nil { if v, ok := d.GetOk("check_interval_sec"); ok {
hchk.TimeoutSec = int64(d.Get("timeout_sec").(int)) hchk.CheckIntervalSec = int64(v.(int))
} }
if d.Get("unhealthy_threshold") != nil { if v, ok := d.GetOk("health_threshold"); ok {
hchk.UnhealthyThreshold = int64(d.Get("unhealthy_threshold").(int)) hchk.HealthyThreshold = int64(v.(int))
}
if v, ok := d.GetOk("port"); ok {
hchk.Port = int64(v.(int))
}
if v, ok := d.GetOk("timeout_sec"); ok {
hchk.TimeoutSec = int64(v.(int))
}
if v, ok := d.GetOk("unhealthy_threshold"); ok {
hchk.UnhealthyThreshold = int64(v.(int))
} }
log.Printf("[DEBUG] HttpHealthCheck patch request: %#v", hchk) log.Printf("[DEBUG] HttpHealthCheck patch request: %#v", hchk)
@ -220,6 +232,13 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error reading HttpHealthCheck: %s", err) return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
} }
d.Set("host", hchk.Host)
d.Set("request_path", hchk.RequestPath)
d.Set("check_interval_sec", hchk.CheckIntervalSec)
d.Set("health_threshold", hchk.HealthyThreshold)
d.Set("port", hchk.Port)
d.Set("timeout_sec", hchk.TimeoutSec)
d.Set("unhealthy_threshold", hchk.UnhealthyThreshold)
d.Set("self_link", hchk.SelfLink) d.Set("self_link", hchk.SelfLink)
return nil return nil

View File

@ -72,7 +72,7 @@ func testAccCheckComputeHttpHealthCheckExists(n string) resource.TestCheckFunc {
const testAccComputeHttpHealthCheck_basic = ` const testAccComputeHttpHealthCheck_basic = `
resource "google_compute_http_health_check" "foobar" { resource "google_compute_http_health_check" "foobar" {
check_interval_sec = 1 check_interval_sec = 3
description = "Resource created for Terraform acceptance testing" description = "Resource created for Terraform acceptance testing"
healthy_threshold = 3 healthy_threshold = 3
host = "foobar" host = "foobar"