From 69acd6272a59211acf0f62a35ef4e261a19f704c Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Fri, 4 Jul 2014 19:03:01 -0400 Subject: [PATCH] providers/aws: elb instance registration --- builtin/providers/aws/resource_aws_elb.go | 52 +++++++++---------- .../providers/aws/resource_aws_instance.go | 2 + 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index b77cb6c12..a306feefb 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -51,26 +51,6 @@ func resource_aws_elb_create( rs.ID = elbName log.Printf("[INFO] ELB ID: %s", elbName) - describeElbOpts := &elb.DescribeLoadBalancer{ - Names: []string{elbName}, - } - - // Retrieve the ELB properties for updating the state - describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts) - if err != nil { - return nil, fmt.Errorf("Error retrieving ELB: %s", err) - } - - // Verify AWS returned our ELB - if len(describeResp.LoadBalancers) != 1 || - describeResp.LoadBalancers[0].LoadBalancerName != elbName { - if err != nil { - return nil, fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancers) - } - } - - loadBalancer := describeResp.LoadBalancers[0] - // If we have any instances, we need to register them v = flatmap.Expand(rs.Attributes, "instances").([]interface{}) instances := expandStringList(v) @@ -81,7 +61,31 @@ func resource_aws_elb_create( Instances: instances, } - registerResp, err := elbconn.RegisterInstancesWithLoadBalancer(registerInstancesOpts) + _, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts) + + if err != nil { + return nil, fmt.Errorf("Failure registering instances: %s", err) + } + } + + describeElbOpts := &elb.DescribeLoadBalancer{ + Names: []string{elbName}, + } + + // Retrieve the ELB properties for updating the state + describeResp, err := elbconn.DescribeLoadBalancers(describeElbOpts) + if err != nil { + return nil, fmt.Errorf("Error retrieving ELB: %s", err) + } + + loadBalancer := describeResp.LoadBalancers[0] + + // Verify AWS returned our ELB + if len(describeResp.LoadBalancers) != 1 || + describeResp.LoadBalancers[0].LoadBalancerName != elbName { + if err != nil { + return nil, fmt.Errorf("Unable to find ELB: %#v", describeResp.LoadBalancers) + } } return resource_aws_elb_update_state(rs, &loadBalancer) @@ -96,11 +100,7 @@ func resource_aws_elb_update( // Merge the diff into the state so that we have all the attributes // properly. - rs := s.MergeDiff(d) - - log.Println(rs) - - rs.Attributes + // rs := s.MergeDiff(d) return nil, nil } diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index cf40918a0..af5acfb22 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -115,6 +115,7 @@ func resource_aws_instance_diff( "public_ip", "private_dns", "private_ip", + "instance_id", }, } @@ -161,6 +162,7 @@ func resource_aws_instance_update_state( s.Attributes["public_ip"] = instance.PublicIpAddress s.Attributes["private_dns"] = instance.PrivateDNSName s.Attributes["private_ip"] = instance.PrivateIpAddress + s.Attributes["instance_id"] = instance.InstanceId return s, nil }