Merge pull request #4564 from hashicorp/pr-3741
provider/aws: Supporting New AWS Route53 HealthCheck additions (supersedes #3741)
This commit is contained in:
commit
8e6fba43ef
|
@ -1,7 +1,9 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -23,14 +25,17 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
StateFunc: func(val interface{}) string {
|
||||||
|
return strings.ToUpper(val.(string))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"failure_threshold": &schema.Schema{
|
"failure_threshold": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
"request_interval": &schema.Schema{
|
"request_interval": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Optional: true,
|
||||||
ForceNew: true, // todo this should be updateable but the awslabs route53 service doesnt have the ability
|
ForceNew: true, // todo this should be updateable but the awslabs route53 service doesnt have the ability
|
||||||
},
|
},
|
||||||
"ip_address": &schema.Schema{
|
"ip_address": &schema.Schema{
|
||||||
|
@ -47,10 +52,16 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"invert_healthcheck": &schema.Schema{
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
"resource_path": &schema.Schema{
|
"resource_path": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"search_string": &schema.Schema{
|
"search_string": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -61,6 +72,26 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
|
||||||
Default: false,
|
Default: false,
|
||||||
ForceNew: true,
|
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(),
|
"tags": tagsSchema(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -89,8 +120,16 @@ func resourceAwsRoute53HealthCheckUpdate(d *schema.ResourceData, meta interface{
|
||||||
updateHealthCheck.ResourcePath = aws.String(d.Get("resource_path").(string))
|
updateHealthCheck.ResourcePath = aws.String(d.Get("resource_path").(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("search_string") {
|
if d.HasChange("invert_healthcheck") {
|
||||||
updateHealthCheck.SearchString = aws.String(d.Get("search_string").(string))
|
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)
|
_, err := conn.UpdateHealthCheck(updateHealthCheck)
|
||||||
|
@ -109,9 +148,15 @@ func resourceAwsRoute53HealthCheckCreate(d *schema.ResourceData, meta interface{
|
||||||
conn := meta.(*AWSClient).r53conn
|
conn := meta.(*AWSClient).r53conn
|
||||||
|
|
||||||
healthConfig := &route53.HealthCheckConfig{
|
healthConfig := &route53.HealthCheckConfig{
|
||||||
Type: aws.String(d.Get("type").(string)),
|
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 {
|
if v, ok := d.GetOk("fqdn"); ok {
|
||||||
|
@ -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{
|
input := &route53.CreateHealthCheckInput{
|
||||||
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
||||||
HealthCheckConfig: healthConfig,
|
HealthCheckConfig: healthConfig,
|
||||||
|
@ -187,6 +246,9 @@ func resourceAwsRoute53HealthCheckRead(d *schema.ResourceData, meta interface{})
|
||||||
d.Set("port", updated.Port)
|
d.Set("port", updated.Port)
|
||||||
d.Set("resource_path", updated.ResourcePath)
|
d.Set("resource_path", updated.ResourcePath)
|
||||||
d.Set("measure_latency", updated.MeasureLatency)
|
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
|
// read the tags
|
||||||
req := &route53.ListTagsForResourceInput{
|
req := &route53.ListTagsForResourceInput{
|
||||||
|
@ -222,3 +284,12 @@ func resourceAwsRoute53HealthCheckDelete(d *schema.ResourceData, meta interface{
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
|
||||||
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
|
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_route53_health_check.foo", "measure_latency", "true"),
|
"aws_route53_health_check.foo", "measure_latency", "true"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_route53_health_check.foo", "invert_healthcheck", "true"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
@ -30,6 +32,24 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
|
||||||
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
|
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_route53_health_check.foo", "failure_threshold", "5"),
|
"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"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -127,6 +147,7 @@ resource "aws_route53_health_check" "foo" {
|
||||||
failure_threshold = "2"
|
failure_threshold = "2"
|
||||||
request_interval = "30"
|
request_interval = "30"
|
||||||
measure_latency = true
|
measure_latency = true
|
||||||
|
invert_healthcheck = true
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "tf-test-health-check"
|
Name = "tf-test-health-check"
|
||||||
|
@ -142,6 +163,8 @@ resource "aws_route53_health_check" "foo" {
|
||||||
resource_path = "/"
|
resource_path = "/"
|
||||||
failure_threshold = "5"
|
failure_threshold = "5"
|
||||||
request_interval = "30"
|
request_interval = "30"
|
||||||
|
measure_latency = true
|
||||||
|
invert_healthcheck = false
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "tf-test-health-check"
|
Name = "tf-test-health-check"
|
||||||
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -12,7 +12,7 @@ Provides a Route53 health check.
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
resource "aws_route53_health_check" "foo" {
|
resource "aws_route53_health_check" "child1" {
|
||||||
fqdn = "foobar.terraform.com"
|
fqdn = "foobar.terraform.com"
|
||||||
port = 80
|
port = 80
|
||||||
type = "HTTP"
|
type = "HTTP"
|
||||||
|
@ -24,6 +24,16 @@ resource "aws_route53_health_check" "foo" {
|
||||||
Name = "tf-test-health-check"
|
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
|
## Argument Reference
|
||||||
|
@ -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.
|
* `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.
|
* `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.
|
* `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.
|
* `tags` - (Optional) A mapping of tags to assign to the health check.
|
||||||
|
|
||||||
At least one of either `fqdn` or `ip_address` must be specified.
|
At least one of either `fqdn` or `ip_address` must be specified.
|
||||||
|
|
Loading…
Reference in New Issue