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

resource/aws_route53_health_check: Various small improvements #6460

Merged
merged 3 commits into from
Nov 14, 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
15 changes: 14 additions & 1 deletion aws/resource_aws_route53_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
StateFunc: func(val interface{}) string {
return strings.ToUpper(val.(string))
},
ValidateFunc: validation.StringInSlice([]string{
route53.HealthCheckTypeCalculated,
route53.HealthCheckTypeCloudwatchMetric,
route53.HealthCheckTypeHttp,
route53.HealthCheckTypeHttpStrMatch,
route53.HealthCheckTypeHttps,
route53.HealthCheckTypeHttpsStrMatch,
route53.HealthCheckTypeTcp,
}, true),
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason this is case-insensitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I worry because the StateFunc right above is explicitly converting things to uppercase. My guess is that the API accepts both casings, so to keep that support for existing configurations, turned off case sensitivity here for validation.

},
"failure_threshold": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -333,7 +342,11 @@ func resourceAwsRoute53HealthCheckRead(d *schema.ResourceData, meta interface{})
d.Set("resource_path", updated.ResourcePath)
d.Set("measure_latency", updated.MeasureLatency)
d.Set("invert_healthcheck", updated.Inverted)
d.Set("child_healthchecks", updated.ChildHealthChecks)

if err := d.Set("child_healthchecks", flattenStringList(updated.ChildHealthChecks)); err != nil {
return fmt.Errorf("error setting child_healthchecks: %s", err)
}

d.Set("child_health_threshold", updated.HealthThreshold)
d.Set("insufficient_data_health_status", updated.InsufficientDataHealthStatus)
d.Set("enable_sni", updated.EnableSNI)
Expand Down
61 changes: 36 additions & 25 deletions aws/resource_aws_route53_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/route53"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

"github.com/aws/aws-sdk-go/service/route53"
)

func TestAccAWSRoute53HealthCheck_importBasic(t *testing.T) {
resourceName := "aws_route53_health_check.foo"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
{
Config: testAccRoute53HealthCheckConfig,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -48,6 +26,11 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
"aws_route53_health_check.foo", "invert_healthcheck", "true"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccRoute53HealthCheckConfigUpdate,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -79,6 +62,11 @@ func TestAccAWSRoute53HealthCheck_withSearchString(t *testing.T) {
"aws_route53_health_check.foo", "search_string", "OK"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccRoute53HealthCheckConfigWithSearchStringUpdate,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -105,6 +93,11 @@ func TestAccAWSRoute53HealthCheck_withChildHealthChecks(t *testing.T) {
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -123,6 +116,11 @@ func TestAccAWSRoute53HealthCheck_withHealthCheckRegions(t *testing.T) {
"aws_route53_health_check.foo", "regions.#", "3"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -139,6 +137,11 @@ func TestAccAWSRoute53HealthCheck_IpConfig(t *testing.T) {
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.bar"),
),
},
{
ResourceName: "aws_route53_health_check.bar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -157,6 +160,11 @@ func TestAccAWSRoute53HealthCheck_CloudWatchAlarmCheck(t *testing.T) {
"aws_route53_health_check.foo", "cloudwatch_alarm_name", "cloudwatch-healthcheck-alarm"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -176,6 +184,11 @@ func TestAccAWSRoute53HealthCheck_withSNI(t *testing.T) {
"aws_route53_health_check.foo", "enable_sni", "true"),
),
},
{
ResourceName: "aws_route53_health_check.foo",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccRoute53HealthCheckConfigWithSNIDisabled,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -233,8 +246,6 @@ func testAccCheckRoute53HealthCheckExists(n string) resource.TestCheckFunc {
return fmt.Errorf("Not found: %s", n)
}

fmt.Print(rs.Primary.ID)

if rs.Primary.ID == "" {
return fmt.Errorf("No health check ID is set")
}
Expand Down
32 changes: 26 additions & 6 deletions website/docs/r/route53_health_check.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ Provides a Route53 health check.

## Example Usage

### Connectivity and HTTP Status Code Check

```hcl
resource "aws_route53_health_check" "child1" {
fqdn = "foobar.terraform.com"
resource "aws_route53_health_check" "example" {
fqdn = "example.com"
port = 80
type = "HTTP"
resource_path = "/"
Expand All @@ -24,19 +26,37 @@ resource "aws_route53_health_check" "child1" {
Name = "tf-test-health-check"
}
}
```

resource "aws_route53_health_check" "foo" {
### Connectivity and String Matching Check

```hcl
resource "aws_route53_health_check" "example" {
failure_threshold = "5"
fqdn = "example.com"
port = 443
request_interval = "30"
resource_path = "/"
search_string = "example"
type = "HTTPS_STR_MATCH"
}
```

### Aggregate Check

```hcl
resource "aws_route53_health_check" "parent" {
type = "CALCULATED"
child_health_threshold = 1
child_healthchecks = ["${aws_route53_health_check.child1.id}"]
child_healthchecks = ["${aws_route53_health_check.child.id}"]

tags = {
Name = "tf-test-calculated-health-check"
}
}
```

## CloudWatch Alarm Example
### CloudWatch Alarm Check

```hcl
resource "aws_cloudwatch_metric_alarm" "foobar" {
Expand Down Expand Up @@ -72,7 +92,7 @@ The following arguments are supported:
* `failure_threshold` - (Required) The number of consecutive health checks that an endpoint must pass or fail.
* `request_interval` - (Required) The number of seconds between the time that Amazon Route 53 gets a response from your endpoint and the time that it sends the next health-check request.
* `resource_path` - (Optional) The path that you want Amazon Route 53 to request when performing health checks.
* `search_string` - (Optional) String searched in the first 5120 bytes of the response body for check to be considered healthy.
* `search_string` - (Optional) String searched in the first 5120 bytes of the response body for check to be considered healthy. Only valid with `HTTP_STR_MATCH` and `HTTPS_STR_MATCH`.
* `measure_latency` - (Optional) A Boolean value that indicates whether you want Route 53 to measure the latency between health checkers in multiple AWS regions and your endpoint and to display CloudWatch latency graphs in the Route 53 console.
* `invert_healthcheck` - (Optional) A boolean value that indicates whether the status of health check should be inverted. For example, if a health check is healthy but Inverted is True , then Route 53 considers the health check to be unhealthy.
* `enable_sni` - (Optional) A boolean value that indicates whether Route53 should send the `fqdn` to the endpoint when performing the health check. This defaults to AWS' defaults: when the `type` is "HTTPS" `enable_sni` defaults to `true`, when `type` is anything else `enable_sni` defaults to `false`.
Expand Down