Skip to content

Commit

Permalink
provider/aws: wait for ASG capacity on update
Browse files Browse the repository at this point in the history
It's a bit confusing to have Terraform poll until instances come up on
ASG creation but not on update. This changes update to also poll if
min_size or desired_capacity are increased.
  • Loading branch information
phinze committed Nov 17, 2015
1 parent 24ee563 commit b4f186e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions builtin/providers/aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e

func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn
shouldWaitForCapacity := false

opts := autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: aws.String(d.Id()),
Expand All @@ -253,6 +254,7 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})

if d.HasChange("desired_capacity") {
opts.DesiredCapacity = aws.Int64(int64(d.Get("desired_capacity").(int)))
shouldWaitForCapacity = true
}

if d.HasChange("launch_configuration") {
Expand All @@ -261,6 +263,7 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})

if d.HasChange("min_size") {
opts.MinSize = aws.Int64(int64(d.Get("min_size").(int)))
shouldWaitForCapacity = true
}

if d.HasChange("max_size") {
Expand Down Expand Up @@ -353,6 +356,10 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
}
}

if shouldWaitForCapacity {
waitForASGCapacity(d, meta)
}

return resourceAwsAutoscalingGroupRead(d, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ The first is default behavior. Terraform waits after ASG creation for
`min_size` (or `desired_capacity`, if specified) healthy instances to show up
in the ASG before continuing.

If `min_size` or `desired_capacity` are increased in a subsequent update,
Terraform will also wait for the correct number of healthy instances before
continuing. Decreases to these numbers in updates do not currently activate any
waiting behavior.

Terraform considers an instance "healthy" when the ASG reports `HealthStatus:
"Healthy"` and `LifecycleState: "InService"`. See the [AWS AutoScaling
Docs](https://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html)
Expand Down

0 comments on commit b4f186e

Please sign in to comment.