From 6e818785afd2b9134c2b338930f10eee0a4e9586 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Wed, 24 Jun 2015 16:37:23 -0500 Subject: [PATCH] provider/aws: Update ASGs to support in-place updates for Load Balancers --- .../aws/resource_aws_autoscaling_group.go | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index bf9b30c6a..abded26af 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -92,7 +92,6 @@ func resourceAwsAutoscalingGroup() *schema.Resource { "load_balancers": &schema.Schema{ Type: schema.TypeSet, Optional: true, - ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, @@ -258,6 +257,42 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error updating Autoscaling group: %s", err) } + if d.HasChange("load_balancers") { + + o, n := d.GetChange("load_balancers") + if o == nil { + o = new(schema.Set) + } + if n == nil { + n = new(schema.Set) + } + + os := o.(*schema.Set) + ns := n.(*schema.Set) + remove := expandStringList(os.Difference(ns).List()) + add := expandStringList(ns.Difference(os).List()) + + if len(remove) > 0 { + _, err := conn.DetachLoadBalancers(&autoscaling.DetachLoadBalancersInput{ + AutoScalingGroupName: aws.String(d.Id()), + LoadBalancerNames: remove, + }) + if err != nil { + return fmt.Errorf("[WARN] Error updating Load Balancers for AutoScaling Group (%s), error: %s", d.Id(), err) + } + } + + if len(add) > 0 { + _, err := conn.AttachLoadBalancers(&autoscaling.AttachLoadBalancersInput{ + AutoScalingGroupName: aws.String(d.Id()), + LoadBalancerNames: add, + }) + if err != nil { + return fmt.Errorf("[WARN] Error updating Load Balancers for AutoScaling Group (%s), error: %s", d.Id(), err) + } + } + } + return resourceAwsAutoscalingGroupRead(d, meta) }