From f75c3168d7ffd4d4d86231f990b151ebb33c77f0 Mon Sep 17 00:00:00 2001 From: Trevor Pounds Date: Sat, 9 Jan 2016 09:51:08 -0800 Subject: [PATCH] Support updating ELB subnets. --- builtin/providers/aws/resource_aws_elb.go | 38 ++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index b25c7f5a6..2ab7317ad 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -84,7 +84,6 @@ func resourceAwsElb() *schema.Resource { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, - ForceNew: true, Computed: true, Set: schema.HashString, }, @@ -599,6 +598,43 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("security_groups") } + if d.HasChange("subnets") { + o, n := d.GetChange("subnets") + os := o.(*schema.Set) + ns := n.(*schema.Set) + + removed := expandStringList(os.Difference(ns).List()) + added := expandStringList(ns.Difference(os).List()) + + if len(added) > 0 { + attachOpts := &elb.AttachLoadBalancerToSubnetsInput{ + LoadBalancerName: aws.String(d.Id()), + Subnets: added, + } + + log.Printf("[DEBUG] ELB attach subnets opts: %s", attachOpts) + _, err := elbconn.AttachLoadBalancerToSubnets(attachOpts) + if err != nil { + return fmt.Errorf("Failure adding ELB subnets: %s", err) + } + } + + if len(removed) > 0 { + detachOpts := &elb.DetachLoadBalancerFromSubnetsInput{ + LoadBalancerName: aws.String(d.Id()), + Subnets: removed, + } + + log.Printf("[DEBUG] ELB detach subnets opts: %s", detachOpts) + _, err := elbconn.DetachLoadBalancerFromSubnets(detachOpts) + if err != nil { + return fmt.Errorf("Failure removing ELB subnets: %s", err) + } + } + + d.SetPartial("subnets") + } + if err := setTagsELB(elbconn, d); err != nil { return err }