Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_eni: change data type of device_index to str when passing it to api as expected by api call #877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_eni - Change parameter ``device_index`` data type to string when passing to `describe_network_inter` api call (https://github.com/ansible-collections/amazon.aws/pull/877).
2 changes: 1 addition & 1 deletion plugins/modules/ec2_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def uniquely_find_eni(connection, module, eni=None):
filters.append({'Name': 'attachment.instance-id',
'Values': [instance_id]})
filters.append({'Name': 'attachment.device-index',
'Values': [device_index]})
'Values': [str(device_index)]})

if name and subnet_id and not filters:
filters.append({'Name': 'tag:Name',
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/ec2_eni/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
- name: test attaching and detaching network interfaces
include_tasks: ./test_attachment.yaml

- name: test attaching and detaching multiple network interfaces
include_tasks: ./test_create_attached_multiple.yml

- name: test modifying source_dest_check
include_tasks: ./test_modifying_source_dest_check.yaml

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
- name: Create instance to test attaching and detaching network interfaces for this test
ec2_instance:
name: "{{ resource_prefix }}-instance"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
instance_type: t2.micro
register: ec2_instances

- name: set variable for the instance ID
set_fact:
instance_id_3: "{{ ec2_instances.instances[0].instance_id }}"

#=================================================================

- name: Create and attach another interface to above instance - check_mode
amazon.aws.ec2_eni:
name: "{{ resource_prefix }}-eni"
instance_id: "{{ instance_id_3 }}"
device_index: 1
subnet_id: "{{ vpc_subnet_id }}"
state: present
attached: true
delete_on_termination: true
check_mode: true
register: result

# Get the instance info and ENI info to verify attachment of second eni
- ec2_instance_info:
instance_ids:
- "{{ instance_id_3 }}"
register: instance_info_result

- assert:
that:
- result is changed
- result is not failed
- instance_info_result.instances[0].network_interfaces | length == 1
- '"Would have created ENI if not in check mode." in result.msg'
- "'ec2:CreateNetworkInterface' not in {{ result.resource_actions }}"

- name: Create and attach another interface to above instance
amazon.aws.ec2_eni:
name: "{{ resource_prefix }}-eni"
instance_id: "{{ instance_id_3 }}"
device_index: 1
subnet_id: "{{ vpc_subnet_id }}"
state: present
attached: true
delete_on_termination: true
register: result

- name: Set variable for the ENI ID
set_fact:
eni_id_attached_multiple: "{{ result.interface.id }}"

# Get the instance info and ENI info to verify attachment of second eni
- ec2_instance_info:
instance_ids:
- "{{ instance_id_3 }}"
register: instance_info_result
- ec2_eni_info:
eni_id: "{{ eni_id_attached_multiple }}"
register: eni_info

- name: Assert that the interface attachment was successful
assert:
that:
- result is changed
- result is not failed
- instance_info_result.instances[0].network_interfaces | length == 2
- eni_info.network_interfaces[0].attachment.instance_id == instance_id_3
- eni_info.network_interfaces[0].attachment.device_index == 1

- name: Create and attach another interface to above instance - check_mode - idempotent
amazon.aws.ec2_eni:
name: "{{ resource_prefix }}-eni"
instance_id: "{{ instance_id_3 }}"
device_index: 1
subnet_id: "{{ vpc_subnet_id }}"
state: present
attached: true
delete_on_termination: true
check_mode: true
register: result

# Get the instance info and ENI info to verify attachment of second eni
- ec2_instance_info:
instance_ids:
- "{{ instance_id_3 }}"
register: instance_info_result

- name: Assert that the interface would have been modified if not in check_mode
assert:
that:
- result is changed
- result is not failed
- instance_info_result.instances[0].network_interfaces | length == 2
- '"Would have modified ENI: {{ eni_id_attached_multiple }} if not in check mode" in result.msg'
- "'ec2:CreateNetworkInterface' not in {{ result.resource_actions }}"
- "'ec2:ModifyNetworkInterfaceAttribute' not in {{ result.resource_actions }}"

#=================================================================

- name: remove the network interface created in this test
ec2_eni:
eni_id: "{{ eni_id_attached_multiple }}"
force_detach: True
state: absent
ignore_errors: true
retries: 5

- name: terminate the instance created in this test
ec2_instance:
state: absent
instance_ids:
- "{{ instance_id_3 }}"
wait: True
ignore_errors: true
retries: 5
when: instance_id_3 is defined