func resource_aws_autoscaling_group_destroy( s *terraform.ResourceState, meta interface{}) error { p := meta.(*ResourceProvider) autoscalingconn := p.autoscalingconn log.Printf("[DEBUG] AutoScaling Group destroy: %v", s.ID) deleteopts := autoscaling.DeleteAutoScalingGroup{Name: s.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 s.Attributes["force_delete"] != "" { deleteopts.ForceDelete = true } _, err := autoscalingconn.DeleteAutoScalingGroup(&deleteopts) if err != nil { autoscalingerr, ok := err.(*autoscaling.Error) if ok && autoscalingerr.Code == "InvalidGroup.NotFound" { return nil } return err } return nil }
func resourceAwsAutoscalingGroupDelete(d *schema.ResourceData, meta interface{}) error { autoscalingconn := meta.(*AWSClient).autoscalingconn // Read the autoscaling group first. If it doesn't exist, we're done. // We need the group in order to check if there are instances attached. // If so, we need to remove those first. g, err := getAwsAutoscalingGroup(d, meta) if err != nil { return err } if g == nil { return nil } if len(g.Instances) > 0 || g.DesiredCapacity > 0 { if err := resourceAwsAutoscalingGroupDrain(d, meta); err != nil { return err } } log.Printf("[DEBUG] AutoScaling Group destroy: %v", d.Id()) deleteopts := autoscaling.DeleteAutoScalingGroup{Name: 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 = true } if _, err := autoscalingconn.DeleteAutoScalingGroup(&deleteopts); err != nil { autoscalingerr, ok := err.(*autoscaling.Error) if ok && autoscalingerr.Code == "InvalidGroup.NotFound" { return nil } return err } return nil }