providers/aws: eip retrieve func, elb fix state saves after create

This commit is contained in:
Jack Pearkes 2014-07-07 17:38:35 -04:00
parent feb32e6f8a
commit e83e0f72b2
2 changed files with 39 additions and 28 deletions

View File

@ -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
}

View File

@ -64,13 +64,13 @@ func resource_aws_elb_create(
_, err := elbconn.RegisterInstancesWithLoadBalancer(&registerInstancesOpts)
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)