Fix Elastic IP association for instances with multiple network interfaces #194
+145
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When deploying BOSH instances with multiple network interfaces (using different
nic_groupconfigurations) and an Elastic IP, the CPI fails duringcreate_vmwith:Root Cause
The
associate_addressAWS API call was using theinstance_idparameter, which according to AWS documentation only works when "the instance must have exactly one attached network interface."This happens in the scenario where we use multiple NICs (nic_groups) and VIP address.
Solution
Modified
network_configurator.rbto use thenetwork_interface_idparameter (pointing to the primary network interface with device_index 0) instead ofinstance_idwhen associating Elastic IPs. This approach works for both single and multiple network interface scenarios.AWS Documentation Reference
From the AWS EC2 AssociateAddress API Documentation:
InstanceId parameter:
NetworkInterfaceId parameter:
Changes
Code Changes
configure_vipmethod inlib/cloud/aws/network_configurator.rb:describe_instancescall to retrieve instance network interfacesdevice_index0)network_interface_idparameter instead ofinstance_idforassociate_addressTest Coverage
Unit Tests (
spec/unit/network_configurator_spec.rb)Added 3 new test cases to validate multi-NIC VIP scenarios:
Test Helpers Added:
create_nic_mock- Creates network interface mocks with proper device_indexmock_describe_instances- Mocks the AWS describe_instances response structuresetup_vip_mocks- Sets up common VIP association mocksAll unit tests pass.
Integration Tests (
spec/integration/manual_network_spec.rb)Added comprehensive integration test: "creates VM with multiple NICs and associates Elastic IP to primary NIC"
Test validates:
nic_group0 and 1)network_interface_id(notinstance_id)Test setup: