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

Add health_check to aws_elb resource #109

Merged
merged 2 commits into from
Jul 30, 2014
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
37 changes: 37 additions & 0 deletions builtin/providers/aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strconv"

"github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/config"
Expand Down Expand Up @@ -75,6 +76,35 @@ func resource_aws_elb_create(
}
}
}

if _, ok := rs.Attributes["health_check.#"]; ok {
v := flatmap.Expand(rs.Attributes, "health_check").([]interface{})
health_check := v[0].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, right now with how we handle embedded objects, this is the best we can do. Extra health checks will just be ignored, which is fine.

healthyThreshold, err := strconv.ParseInt(health_check["healthy_threshold"].(string), 0, 0)
unhealthyThreshold, err := strconv.ParseInt(health_check["unhealthy_threshold"].(string), 0, 0)
interval, err := strconv.ParseInt(health_check["interval"].(string), 0, 0)
timeout, err := strconv.ParseInt(health_check["timeout"].(string), 0, 0)

if err != nil {
return nil, err
}

configureHealthCheckOpts := elb.ConfigureHealthCheck{
LoadBalancerName: elbName,
Check: elb.HealthCheck{
HealthyThreshold: healthyThreshold,
UnhealthyThreshold: unhealthyThreshold,
Interval: interval,
Target: health_check["target"].(string),
Timeout: timeout,
},
}

_, err = elbconn.ConfigureHealthCheck(&configureHealthCheckOpts)
if err != nil {
return rs, fmt.Errorf("Failure configuring health check: %s", err)
}
}

loadBalancer, err := resource_aws_elb_retrieve_balancer(rs.ID, elbconn)
if err != nil {
Expand Down Expand Up @@ -220,6 +250,7 @@ func resource_aws_elb_diff(
"availability_zone": diff.AttrTypeCreate,
"listener": diff.AttrTypeCreate,
"instances": diff.AttrTypeUpdate,
"health_check": diff.AttrTypeCreate,
},

ComputedAttrs: []string{
Expand Down Expand Up @@ -288,6 +319,12 @@ func resource_aws_elb_validation() *config.Validator {
Optional: []string{
"instances.*",
"availability_zones.*",
"health_check.#",
"health_check.0.healthy_threshold",
"health_check.0.unhealthy_threshold",
"health_check.0.interval",
"health_check.0.target",
"health_check.0.timeout",
},
}
}
19 changes: 18 additions & 1 deletion website/source/docs/providers/aws/r/elb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ resource "aws_elb" "bar" {
lb_protocol = "http"
}

health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:8000/"
interval = 30
}

instances = ["${aws_instance.foo.id}"]
}
```
Expand All @@ -35,6 +43,7 @@ The following arguments are supported:
* `availability_zones` - (Optional) The AZ's to serve traffic in.
* `instances` - (Optional) A list of instance ids to place in the ELB pool.
* `listener` - (Required) A list of listener blocks. Listeners documented below.
* `listener` - (Required) A health_check block. Health Check documented below.

Listeners support the following:

Expand All @@ -43,6 +52,15 @@ Listeners support the following:
* `lb_port` - (Required) The port to listen on for the load balancer
* `lb_protocol` - (Required) The protocol to listen on.

Health Check supports the following:

* `healthy_threshold` - (Required) The number of checks before the instance is declared healthy.
* `unhealthy_threshold` - (Required) The number of checks before the instance is declared unhealthy.
* `target` - (Required) The target of the check.
* `interval` - (Required) The interval between checks.
* `timeout` - (Required) The length of time before the check times out.


## Attributes Reference

The following attributes are exported:
Expand All @@ -51,4 +69,3 @@ The following attributes are exported:
* `name` - The name of the ELB
* `dns_name` - The DNS name of the ELB
* `instances` - The list of instances in the ELB