Merge pull request #3191 from hashicorp/f-asg-wait-config

provider/aws: configurable capacity waiting duration
This commit is contained in:
Paul Hinze 2015-10-14 10:34:55 -05:00
commit 5f6c03f515
2 changed files with 48 additions and 11 deletions

View File

@ -119,6 +119,25 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
Set: schema.HashString, Set: schema.HashString,
}, },
"wait_for_capacity_timeout": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "10m",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
duration, err := time.ParseDuration(value)
if err != nil {
errors = append(errors, fmt.Errorf(
"%q cannot be parsed as a duration: %s", k, err))
}
if duration < 0 {
errors = append(errors, fmt.Errorf(
"%q must be greater than zero", k))
}
return
},
},
"tag": autoscalingTagsSchema(), "tag": autoscalingTagsSchema(),
}, },
} }
@ -443,8 +462,6 @@ func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{})
}) })
} }
var waitForASGCapacityTimeout = 10 * time.Minute
// Waits for a minimum number of healthy instances to show up as healthy in the // Waits for a minimum number of healthy instances to show up as healthy in the
// ASG before continuing. Waits up to `waitForASGCapacityTimeout` for // ASG before continuing. Waits up to `waitForASGCapacityTimeout` for
// "desired_capacity", or "min_size" if desired capacity is not specified. // "desired_capacity", or "min_size" if desired capacity is not specified.
@ -459,9 +476,20 @@ func waitForASGCapacity(d *schema.ResourceData, meta interface{}) error {
} }
wantELB := d.Get("min_elb_capacity").(int) wantELB := d.Get("min_elb_capacity").(int)
log.Printf("[DEBUG] Waiting for capacity: %d ASG, %d ELB", wantASG, wantELB) wait, err := time.ParseDuration(d.Get("wait_for_capacity_timeout").(string))
if err != nil {
return err
}
return resource.Retry(waitForASGCapacityTimeout, func() error { if wait == 0 {
log.Printf("[DEBUG] Capacity timeout set to 0, skipping capacity waiting.")
return nil
}
log.Printf("[DEBUG] Waiting %s for capacity: %d ASG, %d ELB",
wait, wantASG, wantELB)
return resource.Retry(wait, func() error {
g, err := getAwsAutoscalingGroup(d, meta) g, err := getAwsAutoscalingGroup(d, meta)
if err != nil { if err != nil {
return resource.RetryError{Err: err} return resource.RetryError{Err: err}

View File

@ -66,6 +66,11 @@ The following arguments are supported:
* `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in.
* `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. * `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated.
* `tag` (Optional) A list of tag blocks. Tags documented below. * `tag` (Optional) A list of tag blocks. Tags documented below.
* `wait_for_capacity_timeout` (Default: "10m") A maximum
[duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should
wait for ASG instances to be healthy before timing out. (See also [Waiting
for Capacity](#waiting-for-capacity) below.) Setting this to "0" causes
Terraform to skip all Capacity Waiting behavior.
Tags support the following: Tags support the following:
@ -113,9 +118,12 @@ Terraform considers an instance "healthy" when the ASG reports `HealthStatus:
Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html) Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html)
for more information on an ASG's lifecycle. for more information on an ASG's lifecycle.
Terraform will wait for healthy instances for up to 10 minutes. If ASG creation Terraform will wait for healthy instances for up to
is taking more than a few minutes, it's worth investigating for scaling activity `wait_for_capacity_timeout`. If ASG creation is taking more than a few minutes,
errors, which can be caused by problems with the selected Launch Configuration. it's worth investigating for scaling activity errors, which can be caused by
problems with the selected Launch Configuration.
Setting `wait_for_capacity_timeout` to `"0"` disables ASG Capacity waiting.
#### Waiting for ELB Capacity #### Waiting for ELB Capacity
@ -124,8 +132,9 @@ Balancers. If `min_elb_capacity` is set, Terraform will wait for that number of
Instances to be `"InService"` in all attached `load_balancers`. This can be Instances to be `"InService"` in all attached `load_balancers`. This can be
used to ensure that service is being provided before Terraform moves on. used to ensure that service is being provided before Terraform moves on.
As with ASG Capacity, Terraform will wait for up to 10 minutes for As with ASG Capacity, Terraform will wait for up to `wait_for_capacity_timeout`
`"InService"` instances. If ASG creation takes more than a few minutes, this (for `"InService"` instances. If ASG creation takes more than a few minutes,
could indicate one of a number of configuration problems. See the [AWS Docs on this could indicate one of a number of configuration problems. See the [AWS
Load Balancer Troubleshooting](https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-troubleshooting.html) Docs on Load Balancer
Troubleshooting](https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-troubleshooting.html)
for more information. for more information.