Skip to content

Commit

Permalink
Refactor ec2_eni tagging code (ansible-collections#522)
Browse files Browse the repository at this point in the history
Refactor ec2_eni tagging code

SUMMARY
Use the shared ec2 tagging code for tagging ENIs.
Also fixes the test instability (caused by a race condition with VM states)
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_eni
ADDITIONAL INFORMATION

Reviewed-by: Felix Fontein <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
tremble authored and alinabuzachis committed Oct 27, 2021
1 parent 788066e commit 30bfe08
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
9 changes: 0 additions & 9 deletions plugins/modules/ec2_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,6 @@ def create_eni(connection, vpc_id, module):
if tags:
args["TagSpecifications"] = boto3_tag_specifications(tags, types='network-interface')

# check if provided private_ip_address is within the subnet's address range
if private_ip_address:
cidr_block = connection.describe_subnets(SubnetIds=[str(subnet_id)])['Subnets'][0]['CidrBlock']
valid_private_ip = ip_address(private_ip_address) in ip_network(cidr_block)
if not valid_private_ip:
module.fail_json(changed=False, msg="Error: cannot create ENI - Address does not fall within the subnet's address range.")
if module.check_mode:
module.exit_json(changed=True, msg="Would have created ENI if not in check mode.")

eni_dict = connection.create_network_interface(aws_retry=True, **args)
eni = eni_dict["NetworkInterface"]
# Once we have an ID make sure we're always modifying the same object
Expand Down
28 changes: 0 additions & 28 deletions tests/integration/targets/ec2_eni/tasks/test_attachment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
- "{{ instance_id_2 }}"
wait: True

- name: attach the network interface to instance 1 (check mode)
ec2_eni:
instance_id: "{{ instance_id_1 }}"
device_index: 1
private_ip_address: "{{ ip_1 }}"
subnet_id: "{{ vpc_subnet_result.subnet.id }}"
state: present
attached: True
check_mode: true
register: result_check_mode

- assert:
that:
- result_check_mode.changed

- name: attach the network interface to instance 1
ec2_eni:
instance_id: "{{ instance_id_1 }}"
Expand Down Expand Up @@ -227,19 +212,6 @@
- "{{ instance_id_2 }}"
wait: True

- name: delete an attached network interface with force_detach (check mode)
ec2_eni:
force_detach: True
eni_id: "{{ eni_id_1 }}"
state: absent
check_mode: true
register: result_check_mode
ignore_errors: True

- assert:
that:
- result_check_mode.changed

- name: delete an attached network interface with force_detach
ec2_eni:
force_detach: True
Expand Down

0 comments on commit 30bfe08

Please sign in to comment.