provider/aws: configurable capacity waiting duration
move wait for capacity timeout from a constant to a configurable
This commit is contained in:
parent
dcaf0f8b87
commit
506aae2f28
|
@ -120,6 +120,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(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -445,8 +464,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.
|
||||||
|
@ -461,9 +478,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}
|
||||||
|
|
|
@ -63,6 +63,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:
|
||||||
|
|
||||||
|
@ -110,9 +115,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
|
||||||
|
|
||||||
|
@ -121,8 +129,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.
|
||||||
|
|
Loading…
Reference in New Issue