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

provider/aws: fix force_delete on ASGs #3485

Merged
merged 1 commit into from
Oct 12, 2015
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
20 changes: 9 additions & 11 deletions builtin/providers/aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
"force_delete": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
Default: false,
},

"health_check_grace_period": &schema.Schema{
Expand Down Expand Up @@ -334,15 +333,9 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
}

log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id())
deleteopts := autoscaling.DeleteAutoScalingGroupInput{AutoScalingGroupName: aws.String(d.Id())}

// You can force an autoscaling group to delete
// even if it's in the process of scaling a resource.
// Normally, you would set the min-size and max-size to 0,0
// and then delete the group. This bypasses that and leaves
// resources potentially dangling.
if d.Get("force_delete").(bool) {
deleteopts.ForceDelete = aws.Bool(true)
deleteopts := autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: aws.String(d.Id()),
ForceDelete: aws.Bool(d.Get("force_delete").(bool)),
}

// We retry the delete operation to handle InUse/InProgress errors coming
Expand Down Expand Up @@ -414,6 +407,11 @@ func getAwsAutoscalingGroup(
func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn

if d.Get("force_delete").(bool) {
log.Printf("[DEBUG] Skipping ASG drain, force_delete was set.")
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick, force_delete may not have been set since it now has a default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean - it's true if we get to line 411. Is it just the log wording you'd like changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

nope, ignore me I misread that

return nil
}

// First, set the capacity to zero so the group will drain
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
opts := autoscaling.UpdateAutoScalingGroupInput{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ The following arguments are supported:
for this number of healthy instances all attached load balancers.
(See also [Waiting for Capacity](#waiting-for-capacity) below.)
* `force_delete` - (Optional) Allows deleting the autoscaling group without waiting
for all instances in the pool to terminate.
for all instances in the pool to terminate. You can force an autoscaling group to delete
even if it's in the process of scaling a resource. Normally, Terraform
drains all the instances before deleting the group. This bypasses that
behavior and potentially leaves resources dangling.
* `load_balancers` (Optional) A list of load balancer names to add to the autoscaling
group names.
* `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in.
Expand Down