diff --git a/builtin/providers/aws/resource_aws_eip.go b/builtin/providers/aws/resource_aws_eip.go index a82cb50ca..3a519396a 100644 --- a/builtin/providers/aws/resource_aws_eip.go +++ b/builtin/providers/aws/resource_aws_eip.go @@ -75,35 +75,12 @@ func resource_aws_eip_create( } } - // Get the full address description for saving to state for - // use in other resources - assocIds := []string{} - publicIps := []string{} - if vpc { - assocIds = []string{rs.ID} - } else { - publicIps = []string{rs.ID} - } - - log.Printf("[DEBUG] EIP describe configuration: %#v, %#v (vpc: %v)", assocIds, publicIps, vpc) - - describeAddresses, err := ec2conn.Addresses(publicIps, assocIds, nil) - + address, err := resource_aws_eip_retrieve_address(rs.ID, vpc, ec2conn) if err != nil { - return rs, fmt.Errorf("Error retrieving EIP: %s", err) + return rs, err } - // Verify AWS returned our EIP - if len(describeAddresses.Addresses) != 1 || - describeAddresses.Addresses[0].AllocationId != rs.ID { - if err != nil { - return rs, fmt.Errorf("Unable to find EIP: %#v", describeAddresses.Addresses) - } - } - - address := describeAddresses.Addresses[0] - - return resource_aws_eip_update_state(rs, &address) + return resource_aws_eip_update_state(rs, address) } func resource_aws_eip_update( @@ -203,3 +180,37 @@ func resource_aws_eip_update_state( return s, nil } + +// Returns a single address by it's ID +func resource_aws_eip_retrieve_address(id string, vpc bool, ec2conn *ec2.EC2) (*ec2.Address, error) { + // Get the full address description for saving to state for + // use in other resources + assocIds := []string{} + publicIps := []string{} + if vpc { + assocIds = []string{id} + } else { + publicIps = []string{id} + } + + log.Printf("[DEBUG] EIP describe configuration: %#v, %#v (vpc: %v)", assocIds, publicIps, vpc) + + describeAddresses, err := ec2conn.Addresses(publicIps, assocIds, nil) + + if err != nil { + return nil, fmt.Errorf("Error retrieving EIP: %s", err) + } + + // Verify AWS returned our EIP + if len(describeAddresses.Addresses) != 1 || + describeAddresses.Addresses[0].AllocationId != id || + describeAddresses.Addresses[0].PublicIp != id { + if err != nil { + return nil, fmt.Errorf("Unable to find EIP: %#v", describeAddresses.Addresses) + } + } + + address := describeAddresses.Addresses[0] + + return &address, nil +} diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index c0a0c133d..d74c7afd6 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -64,13 +64,13 @@ func resource_aws_elb_create( _, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts) if err != nil { - return nil, fmt.Errorf("Failure registering instances: %s", err) + return rs, fmt.Errorf("Failure registering instances: %s", err) } } loadBalancer, err := resource_aws_elb_retrieve_balancer(rs.ID, elbconn) if err != nil { - return nil, err + return rs, err } return resource_aws_elb_update_state(rs, loadBalancer)