Merge pull request #1894 from dcarley/gce_health_check_defaults
provider/gce: Fix updates for http_health_check (set defaults)
This commit is contained in:
commit
e27393af41
|
@ -21,7 +21,7 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
|
||||||
"check_interval_sec": &schema.Schema{
|
"check_interval_sec": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Default: 5,
|
||||||
},
|
},
|
||||||
|
|
||||||
"description": &schema.Schema{
|
"description": &schema.Schema{
|
||||||
|
@ -32,7 +32,7 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
|
||||||
"healthy_threshold": &schema.Schema{
|
"healthy_threshold": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Default: 2,
|
||||||
},
|
},
|
||||||
|
|
||||||
"host": &schema.Schema{
|
"host": &schema.Schema{
|
||||||
|
@ -49,13 +49,13 @@ func resourceComputeHttpHealthCheck() *schema.Resource {
|
||||||
"port": &schema.Schema{
|
"port": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Default: 80,
|
||||||
},
|
},
|
||||||
|
|
||||||
"request_path": &schema.Schema{
|
"request_path": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Default: "/",
|
||||||
},
|
},
|
||||||
|
|
||||||
"self_link": &schema.Schema{
|
"self_link": &schema.Schema{
|
||||||
|
@ -66,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,
|
||||||
Computed: true,
|
Default: 5,
|
||||||
},
|
},
|
||||||
|
|
||||||
"unhealthy_threshold": &schema.Schema{
|
"unhealthy_threshold": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Default: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,12 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"google.golang.org/api/compute/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
|
func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
|
||||||
|
var healthCheck compute.HttpHealthCheck
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
@ -18,7 +21,45 @@ func TestAccComputeHttpHealthCheck_basic(t *testing.T) {
|
||||||
Config: testAccComputeHttpHealthCheck_basic,
|
Config: testAccComputeHttpHealthCheck_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckComputeHttpHealthCheckExists(
|
testAccCheckComputeHttpHealthCheckExists(
|
||||||
"google_compute_http_health_check.foobar"),
|
"google_compute_http_health_check.foobar", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckRequestPath(
|
||||||
|
"/health_check", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckThresholds(
|
||||||
|
3, 3, &healthCheck),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccComputeHttpHealthCheck_update(t *testing.T) {
|
||||||
|
var healthCheck compute.HttpHealthCheck
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeHttpHealthCheck_update1,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeHttpHealthCheckExists(
|
||||||
|
"google_compute_http_health_check.foobar", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckRequestPath(
|
||||||
|
"/not_default", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckThresholds(
|
||||||
|
2, 2, &healthCheck),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeHttpHealthCheck_update2,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeHttpHealthCheckExists(
|
||||||
|
"google_compute_http_health_check.foobar", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckRequestPath(
|
||||||
|
"/", &healthCheck),
|
||||||
|
testAccCheckComputeHttpHealthCheckThresholds(
|
||||||
|
10, 10, &healthCheck),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -43,7 +84,7 @@ func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckComputeHttpHealthCheckExists(n string) resource.TestCheckFunc {
|
func testAccCheckComputeHttpHealthCheckExists(n string, healthCheck *compute.HttpHealthCheck) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -66,6 +107,32 @@ func testAccCheckComputeHttpHealthCheckExists(n string) resource.TestCheckFunc {
|
||||||
return fmt.Errorf("HttpHealthCheck not found")
|
return fmt.Errorf("HttpHealthCheck not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*healthCheck = *found
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeHttpHealthCheckRequestPath(path string, healthCheck *compute.HttpHealthCheck) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
if healthCheck.RequestPath != path {
|
||||||
|
return fmt.Errorf("RequestPath doesn't match: expected %d, got %d", path, healthCheck.RequestPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeHttpHealthCheckThresholds(healthy, unhealthy int64, healthCheck *compute.HttpHealthCheck) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
if healthCheck.HealthyThreshold != healthy {
|
||||||
|
return fmt.Errorf("HealthyThreshold doesn't match: expected %d, got %d", healthy, healthCheck.HealthyThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if healthCheck.UnhealthyThreshold != unhealthy {
|
||||||
|
return fmt.Errorf("UnhealthyThreshold doesn't match: expected %d, got %d", unhealthy, healthCheck.UnhealthyThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,3 +150,22 @@ resource "google_compute_http_health_check" "foobar" {
|
||||||
unhealthy_threshold = 3
|
unhealthy_threshold = 3
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccComputeHttpHealthCheck_update1 = `
|
||||||
|
resource "google_compute_http_health_check" "foobar" {
|
||||||
|
name = "terraform-test"
|
||||||
|
description = "Resource created for Terraform acceptance testing"
|
||||||
|
request_path = "/not_default"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
/* Change description, restore request_path to default, and change
|
||||||
|
* thresholds from defaults */
|
||||||
|
const testAccComputeHttpHealthCheck_update2 = `
|
||||||
|
resource "google_compute_http_health_check" "foobar" {
|
||||||
|
name = "terraform-test"
|
||||||
|
description = "Resource updated for Terraform acceptance testing"
|
||||||
|
healthy_threshold = 10
|
||||||
|
unhealthy_threshold = 10
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue