Skip to content

Commit

Permalink
Fixup ec2_eip tests - work around ec2_instance flakes (#333)
Browse files Browse the repository at this point in the history
* Explicitly pass the subnet the instance should live on - try to avoid https://github.com/ansible-collections/community.aws/issues/329

* Make sure we delete the Instance (and free the EIP) before we try to drop the IGW

* Use IDs when cleaning up EC2 instances
  • Loading branch information
tremble authored Dec 14, 2020
1 parent be0042c commit 6c0273b
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions tests/integration/targets/ec2_eip/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@
name: '{{ resource_prefix }}-instance'
image_id: '{{ ec2_amis.images[0].image_id }}'
security_group: '{{ security_group.group_id }}'
vpc_subnet_id: '{{ vpc_subnet_create.subnet.id }}'
wait: no ## Don't delay the tests, we'll check again before we need it
register: ec2_instance_result
register: create_ec2_instance_result

# =====================================================
- name: Look for signs of concurrent EIP tests. Pause if they are running or their prefix comes before ours.
vars:
Expand Down Expand Up @@ -570,19 +572,23 @@
- eip_info.addresses[0].allocation_id is defined
- eip_info.addresses[0].instance_id == '{{ instance_info.instances[0].instance_id }}'
# =====================================================
- name: Cleanup IGW
ec2_vpc_igw:
state: absent
vpc_id: '{{ vpc_result.vpc.id }}'
register: vpc_igw
- name: Cleanup instance
ec2_instance:
name: '{{ resource_prefix }}-instance'
instance_ids: '{{ create_ec2_instance_result.instance_ids }}'
state: absent
- name: Cleanup instance eip
ec2_eip:
state: absent
public_ip: '{{ instance_eip.public_ip }}'
register: eip_cleanup
retries: 5
delay: 5
until: eip_cleanup is successful
- name: Cleanup IGW
ec2_vpc_igw:
state: absent
vpc_id: '{{ vpc_result.vpc.id }}'
register: vpc_igw
- name: Cleanup security group
ec2_group:
state: absent
Expand Down Expand Up @@ -642,6 +648,18 @@
cidr_block: '{{ vpc_cidr }}'
# =====================================================
always:
- name: Cleanup instance (by id)
ec2_instance:
instance_ids: '{{ create_ec2_instance_result.instance_ids }}'
state: absent
wait: true
ignore_errors: true
- name: Cleanup instance (by name)
ec2_instance:
name: '{{ resource_prefix }}-instance'
state: absent
wait: true
ignore_errors: true
- name: Cleanup ENI A
ec2_eni:
state: absent
Expand All @@ -652,20 +670,19 @@
state: absent
eni_id: '{{ eni_create_b.interface.id }}'
ignore_errors: true
- name: Cleanup instance eip
ec2_eip:
state: absent
public_ip: '{{ instance_eip.public_ip }}'
retries: 5
delay: 5
until: eip_cleanup is successful
ignore_errors: true
- name: Cleanup IGW
ec2_vpc_igw:
state: absent
vpc_id: '{{ vpc_result.vpc.id }}'
register: vpc_igw
- name: Cleanup instance
ec2_instance:
name: '{{ resource_prefix }}-instance'
state: absent
ignore_errors: true
- name: Cleanup instance eip
ec2_eip:
state: absent
public_ip: '{{ instance_eip.public_ip }}'
ignore_errors: true
- name: Cleanup security group
ec2_group:
Expand Down

0 comments on commit 6c0273b

Please sign in to comment.