Adding child_healthchecks to the Route 53 HealthCheck resource
This commit is contained in:
parent
172faca052
commit
3ebbb62bb0
|
@ -1,6 +1,7 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
|
@ -26,11 +27,11 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
|
|||
},
|
||||
"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{
|
||||
|
@ -68,6 +69,25 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
|
|||
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(),
|
||||
},
|
||||
}
|
||||
|
@ -100,6 +120,14 @@ func resourceAwsRoute53HealthCheckUpdate(d *schema.ResourceData, meta interface{
|
|||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -117,8 +145,14 @@ func resourceAwsRoute53HealthCheckCreate(d *schema.ResourceData, meta interface{
|
|||
|
||||
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))),
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -209,6 +243,8 @@ func resourceAwsRoute53HealthCheckRead(d *schema.ResourceData, meta interface{})
|
|||
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{
|
||||
|
|
|
@ -40,6 +40,22 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
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"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSRoute53HealthCheck_IpConfig(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -170,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"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -38,6 +48,8 @@ The following arguments are supported:
|
|||
* `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.
|
||||
|
|
Loading…
Reference in New Issue