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

provider/aws: Supporting New AWS Route53 HealthCheck additions (supersedes #3741) #4564

Merged
merged 3 commits into from
Jan 14, 2016
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
85 changes: 78 additions & 7 deletions builtin/providers/aws/resource_aws_route53_health_check.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package aws

import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -23,14 +25,17 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: func(val interface{}) string {
return strings.ToUpper(val.(string))
},
},
"failure_threshold": &schema.Schema{
Type: schema.TypeInt,
Required: true,
Optional: true,
},
"request_interval": &schema.Schema{
Type: schema.TypeInt,
Required: true,
Optional: true,
ForceNew: true, // todo this should be updateable but the awslabs route53 service doesnt have the ability
},
"ip_address": &schema.Schema{
Expand All @@ -47,10 +52,16 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
Optional: true,
},

"invert_healthcheck": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},

"resource_path": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},

"search_string": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand All @@ -61,6 +72,26 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
Default: false,
ForceNew: true,
},

"child_healthchecks": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Set: schema.HashString,
},
"child_health_threshold": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
value := v.(int)
if value > 256 {
es = append(es, fmt.Errorf(
"Child HealthThreshold cannot be more than 256"))
}
return
},
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -89,8 +120,16 @@ func resourceAwsRoute53HealthCheckUpdate(d *schema.ResourceData, meta interface{
updateHealthCheck.ResourcePath = aws.String(d.Get("resource_path").(string))
}

if d.HasChange("search_string") {
updateHealthCheck.SearchString = aws.String(d.Get("search_string").(string))
if d.HasChange("invert_healthcheck") {
updateHealthCheck.Inverted = aws.Bool(d.Get("invert_healthcheck").(bool))
}

if d.HasChange("child_healthchecks") {
updateHealthCheck.ChildHealthChecks = expandStringList(d.Get("child_healthchecks").(*schema.Set).List())

}
if d.HasChange("child_health_threshold") {
updateHealthCheck.HealthThreshold = aws.Int64(int64(d.Get("child_health_threshold").(int)))
}

_, err := conn.UpdateHealthCheck(updateHealthCheck)
Expand All @@ -109,9 +148,15 @@ func resourceAwsRoute53HealthCheckCreate(d *schema.ResourceData, meta interface{
conn := meta.(*AWSClient).r53conn

healthConfig := &route53.HealthCheckConfig{
Type: aws.String(d.Get("type").(string)),
FailureThreshold: aws.Int64(int64(d.Get("failure_threshold").(int))),
RequestInterval: aws.Int64(int64(d.Get("request_interval").(int))),
Type: aws.String(d.Get("type").(string)),
}

if v, ok := d.GetOk("request_interval"); ok {
healthConfig.RequestInterval = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("failure_threshold"); ok {
healthConfig.FailureThreshold = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("fqdn"); ok {
Expand Down Expand Up @@ -140,6 +185,20 @@ func resourceAwsRoute53HealthCheckCreate(d *schema.ResourceData, meta interface{
}
}

if v, ok := d.GetOk("invert_healthcheck"); ok {
healthConfig.Inverted = aws.Bool(v.(bool))
}

if *healthConfig.Type == route53.HealthCheckTypeCalculated {
if v, ok := d.GetOk("child_healthchecks"); ok {
healthConfig.ChildHealthChecks = expandStringList(v.(*schema.Set).List())
}

if v, ok := d.GetOk("child_health_threshold"); ok {
healthConfig.HealthThreshold = aws.Int64(int64(v.(int)))
}
}

input := &route53.CreateHealthCheckInput{
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
HealthCheckConfig: healthConfig,
Expand Down Expand Up @@ -187,6 +246,9 @@ func resourceAwsRoute53HealthCheckRead(d *schema.ResourceData, meta interface{})
d.Set("port", updated.Port)
d.Set("resource_path", updated.ResourcePath)
d.Set("measure_latency", updated.MeasureLatency)
d.Set("invent_healthcheck", updated.Inverted)
d.Set("child_healthchecks", updated.ChildHealthChecks)
d.Set("child_health_threshold", updated.HealthThreshold)

// read the tags
req := &route53.ListTagsForResourceInput{
Expand Down Expand Up @@ -222,3 +284,12 @@ func resourceAwsRoute53HealthCheckDelete(d *schema.ResourceData, meta interface{

return nil
}

func createChildHealthCheckList(s *schema.Set) (nl []*string) {
l := s.List()
for _, n := range l {
nl = append(nl, aws.String(n.(string)))
}

return nl
}
44 changes: 44 additions & 0 deletions builtin/providers/aws/resource_aws_route53_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "measure_latency", "true"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "invert_healthcheck", "true"),
),
},
resource.TestStep{
Expand All @@ -30,6 +32,24 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "failure_threshold", "5"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "invert_healthcheck", "false"),
),
},
},
})
}

func TestAccAWSRoute53HealthCheck_withChildHealthChecks(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRoute53HealthCheckConfig_withChildHealthChecks,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
),
},
},
Expand Down Expand Up @@ -127,6 +147,7 @@ resource "aws_route53_health_check" "foo" {
failure_threshold = "2"
request_interval = "30"
measure_latency = true
invert_healthcheck = true

tags = {
Name = "tf-test-health-check"
Expand All @@ -142,6 +163,8 @@ resource "aws_route53_health_check" "foo" {
resource_path = "/"
failure_threshold = "5"
request_interval = "30"
measure_latency = true
invert_healthcheck = false

tags = {
Name = "tf-test-health-check"
Expand All @@ -163,3 +186,24 @@ resource "aws_route53_health_check" "bar" {
}
}
`

const testAccRoute53HealthCheckConfig_withChildHealthChecks = `
resource "aws_route53_health_check" "child1" {
fqdn = "child1.notexample.com"
port = 80
type = "HTTP"
resource_path = "/"
failure_threshold = "2"
request_interval = "30"
}

resource "aws_route53_health_check" "foo" {
type = "CALCULATED"
child_health_threshold = 1
child_healthchecks = ["${aws_route53_health_check.child1.id}"]

tags = {
Name = "tf-test-calculated-health-check"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Provides a Route53 health check.
## Example Usage

```
resource "aws_route53_health_check" "foo" {
resource "aws_route53_health_check" "child1" {
fqdn = "foobar.terraform.com"
port = 80
type = "HTTP"
Expand All @@ -24,6 +24,16 @@ resource "aws_route53_health_check" "foo" {
Name = "tf-test-health-check"
}
}

resource "aws_route53_health_check" "foo" {
type = "CALCULATED"
child_health_threshold = 1
child_healthchecks = ["${aws_route53_health_check.child1.id}"]

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

## Argument Reference
Expand All @@ -36,6 +46,10 @@ The following arguments are supported:
* `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 respoonse body for check to considered healthy.
* `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.
* `child_healthchecks` - (Optional) For a specified parent health check, a list of HealthCheckId values for the associated child health checks.
* `child_health_threshold` - (Optional) The minimum number of child health checks that must be healthy for Route 53 to consider the parent health check to be healthy. Valid values are integers between 0 and 256, inclusive
* `tags` - (Optional) A mapping of tags to assign to the health check.

At least one of either `fqdn` or `ip_address` must be specified.
Expand Down