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: add support for health_check regions #1116

Merged
merged 1 commit into from
Jul 11, 2017
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
51 changes: 34 additions & 17 deletions aws/resource_aws_route53_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,66 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: func(val interface{}) string {
return strings.ToUpper(val.(string))
},
},
"failure_threshold": &schema.Schema{
"failure_threshold": {
Type: schema.TypeInt,
Optional: true,
},
"request_interval": &schema.Schema{
"request_interval": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true, // todo this should be updateable but the awslabs route53 service doesnt have the ability
},
"ip_address": &schema.Schema{
"ip_address": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"fqdn": &schema.Schema{
"fqdn": {
Type: schema.TypeString,
Optional: true,
},
"port": &schema.Schema{
"port": {
Type: schema.TypeInt,
Optional: true,
},

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

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

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

"measure_latency": &schema.Schema{
"measure_latency": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"child_healthchecks": &schema.Schema{
"child_healthchecks": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Set: schema.HashString,
},
"child_health_threshold": &schema.Schema{
"child_health_threshold": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
Expand All @@ -96,31 +96,38 @@ func resourceAwsRoute53HealthCheck() *schema.Resource {
},
},

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

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

"insufficient_data_health_status": &schema.Schema{
"insufficient_data_health_status": {
Type: schema.TypeString,
Optional: true,
},
"reference_name": &schema.Schema{
"reference_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"enable_sni": &schema.Schema{
"enable_sni": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"regions": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Set: schema.HashString,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -182,6 +189,10 @@ func resourceAwsRoute53HealthCheckUpdate(d *schema.ResourceData, meta interface{
updateHealthCheck.EnableSNI = aws.Bool(d.Get("enable_sni").(bool))
}

if d.HasChange("regions") {
updateHealthCheck.Regions = expandStringList(d.Get("regions").(*schema.Set).List())
}

_, err := conn.UpdateHealthCheck(updateHealthCheck)
if err != nil {
return err
Expand Down Expand Up @@ -271,6 +282,10 @@ func resourceAwsRoute53HealthCheckCreate(d *schema.ResourceData, meta interface{
}
}

if v, ok := d.GetOk("regions"); ok {
healthConfig.Regions = expandStringList(v.(*schema.Set).List())
}

callerRef := resource.UniqueId()
if v, ok := d.GetOk("reference_name"); ok {
callerRef = fmt.Sprintf("%s-%s", v.(string), callerRef)
Expand Down Expand Up @@ -329,6 +344,8 @@ func resourceAwsRoute53HealthCheckRead(d *schema.ResourceData, meta interface{})
d.Set("insufficient_data_health_status", updated.InsufficientDataHealthStatus)
d.Set("enable_sni", updated.EnableSNI)

d.Set("regions", flattenStringList(updated.Regions))

if updated.AlarmIdentifier != nil {
d.Set("cloudwatch_alarm_name", updated.AlarmIdentifier.Name)
d.Set("cloudwatch_alarm_region", updated.AlarmIdentifier.Region)
Expand Down
55 changes: 45 additions & 10 deletions aws/resource_aws_route53_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -27,7 +27,7 @@ func TestAccAWSRoute53HealthCheck_basic(t *testing.T) {
"aws_route53_health_check.foo", "invert_healthcheck", "true"),
),
},
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -48,7 +48,7 @@ func TestAccAWSRoute53HealthCheck_withSearchString(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigWithSearchString,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -58,7 +58,7 @@ func TestAccAWSRoute53HealthCheck_withSearchString(t *testing.T) {
"aws_route53_health_check.foo", "search_string", "OK"),
),
},
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigWithSearchStringUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -78,7 +78,7 @@ func TestAccAWSRoute53HealthCheck_withChildHealthChecks(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfig_withChildHealthChecks,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -88,13 +88,31 @@ func TestAccAWSRoute53HealthCheck_withChildHealthChecks(t *testing.T) {
})
}

func TestAccAWSRoute53HealthCheck_withHealthCheckRegions(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
{
Config: testAccRoute53HealthCheckConfig_withHealthCheckRegions,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "regions.#", "3"),
),
},
},
})
}

func TestAccAWSRoute53HealthCheck_IpConfig(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckIpConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.bar"),
Expand All @@ -110,7 +128,7 @@ func TestAccAWSRoute53HealthCheck_CloudWatchAlarmCheck(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckCloudWatchAlarm,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand All @@ -129,23 +147,23 @@ func TestAccAWSRoute53HealthCheck_withSNI(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53HealthCheckDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigWithoutSNI,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "enable_sni", "true"),
),
},
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigWithSNIDisabled,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
resource.TestCheckResourceAttr(
"aws_route53_health_check.foo", "enable_sni", "false"),
),
},
resource.TestStep{
{
Config: testAccRoute53HealthCheckConfigWithSNI,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53HealthCheckExists("aws_route53_health_check.foo"),
Expand Down Expand Up @@ -293,6 +311,23 @@ resource "aws_route53_health_check" "foo" {
}
`

const testAccRoute53HealthCheckConfig_withHealthCheckRegions = `
resource "aws_route53_health_check" "foo" {
ip_address = "1.2.3.4"
port = 80
type = "HTTP"
resource_path = "/"
failure_threshold = "2"
request_interval = "30"

regions = ["us-west-1","us-east-1","eu-west-1"]

tags = {
Name = "tf-test-check-with-regions"
}
}
`

const testAccRoute53HealthCheckCloudWatchAlarm = `
resource "aws_cloudwatch_metric_alarm" "foobar" {
alarm_name = "cloudwatch-healthcheck-alarm"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/route53_health_check.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The following arguments are supported:
* `cloudwatch_alarm_name` - (Optional) The name of the CloudWatch alarm.
* `cloudwatch_alarm_region` - (Optional) The CloudWatchRegion that the CloudWatch alarm was created in.
* `insufficient_data_health_status` - (Optional) The status of the health check when CloudWatch has insufficient data about the state of associated alarm. Valid values are `Healthy` , `Unhealthy` and `LastKnownStatus`.
* `regions` - (Optional) A list of AWS regions that you want Amazon Route 53 health checkers to check the specified endpoint from.

* `tags` - (Optional) A mapping of tags to assign to the health check.

Expand Down