if (privateIp == null) {
// TODO: Prune private ip addresses from NICs?
// TODO: Need to tag??
{
AssignPrivateIpAddressesRequest request = new AssignPrivateIpAddressesRequest();
request.setNetworkInterfaceId(networkInterface.getNetworkInterfaceId());
request.setSecondaryPrivateIpAddressCount(1);
ec2.assignPrivateIpAddresses(request);
}
ec2Instance = describeInstance(ec2, ec2InstanceId);
networkInterface = findNetworkInterface(ec2Instance, networkInterfaceIndex);
privateIp = findUnusedIp(networkInterface);
if (privateIp == null) {
throw new IllegalStateException("Unable to find private IP address");
}
}
String privateIpAddress = privateIp.getPrivateIpAddress();
{
AssociateAddressRequest request = new AssociateAddressRequest();
request.setPublicIp(vip.getData().getIp());
request.setPrivateIpAddress(privateIpAddress);
request.setNetworkInterfaceId(networkInterface.getNetworkInterfaceId());
request.setInstanceId(ec2InstanceId);
AssociateAddressResult response = ec2.associateAddress(request);
log.info("Associated public IP with assocation id: {}", response.getAssociationId());
}