Merge pull request #3485 from hashicorp/b-aws-asg-force-delete

provider/aws: fix force_delete on ASGs
This commit is contained in:
Paul Hinze 2015-10-12 17:18:38 -05:00
commit 2978a9fb52
2 changed files with 13 additions and 12 deletions

View File

@ -73,8 +73,7 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
"force_delete": &schema.Schema{ "force_delete": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true, Default: false,
ForceNew: true,
}, },
"health_check_grace_period": &schema.Schema{ "health_check_grace_period": &schema.Schema{
@ -334,15 +333,9 @@ func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{})
} }
log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id()) log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id())
deleteopts := autoscaling.DeleteAutoScalingGroupInput{AutoScalingGroupName: aws.String(d.Id())} deleteopts := autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: aws.String(d.Id()),
// You can force an autoscaling group to delete ForceDelete: aws.Bool(d.Get("force_delete").(bool)),
// 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)
} }
// We retry the delete operation to handle InUse/InProgress errors coming // We retry the delete operation to handle InUse/InProgress errors coming
@ -414,6 +407,11 @@ func getAwsAutoscalingGroup(
func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{}) error { func resourceAwsAutoscalingGroupDrain(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn conn := meta.(*AWSClient).autoscalingconn
if d.Get("force_delete").(bool) {
log.Printf("[DEBUG] Skipping ASG drain, force_delete was set.")
return nil
}
// First, set the capacity to zero so the group will drain // First, set the capacity to zero so the group will drain
log.Printf("[DEBUG] Reducing autoscaling group capacity to zero") log.Printf("[DEBUG] Reducing autoscaling group capacity to zero")
opts := autoscaling.UpdateAutoScalingGroupInput{ opts := autoscaling.UpdateAutoScalingGroupInput{

View File

@ -57,7 +57,10 @@ The following arguments are supported:
for this number of healthy instances all attached load balancers. for this number of healthy instances all attached load balancers.
(See also [Waiting for Capacity](#waiting-for-capacity) below.) (See also [Waiting for Capacity](#waiting-for-capacity) below.)
* `force_delete` - (Optional) Allows deleting the autoscaling group without waiting * `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 * `load_balancers` (Optional) A list of load balancer names to add to the autoscaling
group names. group names.
* `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.