providers/aws: eip retrieve func, elb fix state saves after create
This commit is contained in:
parent
feb32e6f8a
commit
e83e0f72b2
|
@ -75,35 +75,12 @@ func resource_aws_eip_create(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the full address description for saving to state for
|
address, err := resource_aws_eip_retrieve_address(rs.ID, vpc, ec2conn)
|
||||||
// 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)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rs, fmt.Errorf("Error retrieving EIP: %s", err)
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify AWS returned our EIP
|
return resource_aws_eip_update_state(rs, address)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resource_aws_eip_update(
|
func resource_aws_eip_update(
|
||||||
|
@ -203,3 +180,37 @@ func resource_aws_eip_update_state(
|
||||||
|
|
||||||
return s, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -64,13 +64,13 @@ func resource_aws_elb_create(
|
||||||
_, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts)
|
_, err := elbconn.RegisterInstancesWithLoadBalancer(®isterInstancesOpts)
|
||||||
|
|
||||||
if err != nil {
|
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)
|
loadBalancer, err := resource_aws_elb_retrieve_balancer(rs.ID, elbconn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resource_aws_elb_update_state(rs, loadBalancer)
|
return resource_aws_elb_update_state(rs, loadBalancer)
|
||||||
|
|
Loading…
Reference in New Issue