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

Re-enable ec2_vpc_endpoint tests #1167

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 @@
trivial:
- ec2_vpc_endpoint - Re-enable ec2_vpc_endpoint tests
4 changes: 3 additions & 1 deletion tests/integration/targets/ec2_vpc_endpoint/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
time=7m

cloud/aws
disabled

ec2_vpc_endpoint_info
3 changes: 2 additions & 1 deletion tests/integration/targets/ec2_vpc_endpoint/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dependencies: []
dependencies:
- role: setup_ec2_vpc
73 changes: 22 additions & 51 deletions tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
service: '{{ endpoint_service_a }}'
route_table_ids:
- '{{ rtb_igw_id }}'
purge_tags: false
tags:
new_tag: ANewTag
register: add_tag_vpc_endpoint
Expand Down Expand Up @@ -767,7 +768,7 @@
name: securitygroup-prodext
description: "security group for Ansible interface endpoint"
state: present
vpc_id: "{{ vpc.vpc.id }}"
vpc_id: "{{ vpc_id }}"
rules:
- proto: tcp
from_port: 1
Expand All @@ -779,10 +780,11 @@
ec2_vpc_endpoint:
state: present
vpc_id: '{{ vpc_id }}'
service: '{{ endpoint_service_a }}'
service: '{{ endpoint_service_b }}'
vpc_endpoint_type: Interface
vpc_endpoint_subnets: "{{ interface_endpoint_create_subnet_check.subnet.id') }}"
vpc_endpoint_subnets: "{{ interface_endpoint_create_subnet_check.subnet.id }}"
vpc_endpoint_security_groups: "{{ interface_endpoint_create_sg_check.group_id }}"
wait: true
register: create_interface_endpoint_with_sg_subnets
- name: Check that the interface endpoint was created properly
assert:
Expand All @@ -794,6 +796,7 @@
ec2_vpc_endpoint:
state: absent
vpc_endpoint_id: "{{ create_interface_endpoint_with_sg_subnets.result.vpc_endpoint_id }}"
wait: true
register: create_interface_endpoint_with_sg_subnets_delete_check
- assert:
that:
Expand All @@ -802,62 +805,30 @@
# ============================================================
# BEGIN POST-TEST CLEANUP
always:
# Delete the routes first - you can't delete an endpoint with a route
# attached.
- name: Delete minimal route table (no routes)
ec2_vpc_route_table:
state: absent
lookup: id
route_table_id: '{{ rtb_creation_empty.route_table.id }}'
ignore_errors: true

- name: Delete minimal route table (IGW route)
ec2_vpc_route_table:
state: absent
lookup: id
route_table_id: '{{ rtb_creation_igw.route_table.id }}'
ignore_errors: true

- name: Delete endpoint
ec2_vpc_endpoint:
state: absent
vpc_endpoint_id: '{{ create_endpoint.result.vpc_endpoint_id }}'
ignore_errors: true

- name: Delete endpoint
ec2_vpc_endpoint:
state: absent
vpc_endpoint_id: '{{ create_rtb_endpoint.result.vpc_endpoint_id }}'
ignore_errors: true

- name: Query any remain endpoints we created (idempotency work is ongoing) # FIXME
- name: Query any remain endpoints we created
ec2_vpc_endpoint_info:
query: endpoints
filters:
vpc-id:
- '{{ vpc_id }}'
register: test_endpoints
register: remaining_endpoints

- name: Delete all endpoints
ec2_vpc_endpoint:
state: absent
vpc_endpoint_id: '{{ item.vpc_endpoint_id }}'
with_items: '{{ test_endpoints.vpc_endpoints }}'
ignore_errors: true

- name: Remove IGW
ec2_vpc_igw:
state: absent
vpc_id: '{{ vpc_id }}'
register: igw_deletion
retries: 10
delay: 5
until: igw_deletion is success
ignore_errors: yes

- name: Remove VPC
ec2_vpc_net:
state: absent
name: '{{ vpc_name }}'
cidr_block: '{{ vpc_cidr }}'
wait: true
loop: '{{ remaining_endpoints.vpc_endpoints }}'
ignore_errors: true
register: endpoints_removed
until:
- endpoints_removed is not failed
- endpoints_removed is not changed
retries: 20
delay: 10
Comment on lines +827 to +828
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"wait: true" is documented as only working for creation, not deletion :( This isn't a bug, but would be a nice feature. Out of scope for just getting the tests running.


- include_role:
name: 'setup_ec2_vpc'
tasks_from: 'cleanup.yml'
vars:
vpc_id: '{{ vpc_creation.vpc.id }}'
1 change: 1 addition & 0 deletions tests/integration/targets/setup_ec2_vpc/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disabled
Empty file.
1 change: 1 addition & 0 deletions tests/integration/targets/setup_ec2_vpc/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
126 changes: 126 additions & 0 deletions tests/integration/targets/setup_ec2_vpc/tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# ============================================================
- name: Run all tests
module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit)}}'
region: '{{ aws_region }}'
block:

# ============================================================
# Describe state of remaining resources

- name: '(VPC Cleanup) Find all remaining ENIs'
ec2_eni_info:
filters:
vpc-id: '{{ vpc_id }}'
register: remaining_enis

- name: '(VPC Cleanup) Retrieve security group info based on VPC ID'
ec2_group_info:
filters:
vpc-id: '{{ vpc_id }}'
register: remaining_groups

- name: '(VPC Cleanup) Retrieve subnet info based on VPC ID'
ec2_vpc_subnet_info:
filters:
vpc-id: '{{ vpc_id }}'
register: remaining_subnets

- name: '(VPC Cleanup) Retrieve route table info based on VPC ID'
ec2_vpc_route_table_info:
filters:
vpc-id: '{{ vpc_id }}'
register: remaining_rtbs

- name: '(VPC Cleanup) Retrieve VPC info based on VPC ID'
ec2_vpc_net_info:
vpc_ids:
- '{{ vpc_id }}'
register: remaining_vpc

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

- name: '(Cleanup) Delete all ENIs'
ec2_eni:
state: absent
eni_id: '{{ item.id }}'
register: eni_removed
until: eni_removed is not failed
loop: '{{ remaining_enis.network_interfaces }}'
ignore_errors: yes
retries: 10

# ============================================================
# Delete all remaining SGs

# Cross-dependencies between rules in the SGs can cause us problems if we don't clear the rules
# first
- name: '(VPC Cleanup) Delete rules from remaining SGs'
ec2_group:
name: '{{ item.group_name }}'
group_id: '{{ item.group_id }}'
description: '{{ item.description }}'
rules: []
rules_egress: []
loop: '{{ remaining_groups.security_groups }}'
ignore_errors: yes

- name: '(VPC Cleanup) Delete remaining SGs'
ec2_group:
state: absent
group_id: '{{ item.group_id }}'
loop: '{{ remaining_groups.security_groups }}'
ignore_errors: yes

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

- name: '(VPC Cleanup) Delete remaining subnets'
ec2_vpc_subnet:
state: absent
vpc_id: '{{ vpc_id }}'
cidr: '{{ item.cidr_block }}'
register: subnets_removed
loop: '{{ remaining_subnets.subnets }}'
until: subnets_removed is not failed
when:
- item.name != 'default'
ignore_errors: yes
retries: 10

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

- name: '(VPC Cleanup) Delete IGW'
ec2_vpc_igw:
state: absent
vpc_id: '{{ vpc_id }}'
register: igw_deletion
retries: 10
delay: 5
until: igw_deletion is success
ignore_errors: yes

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

- name: '(VPC Cleanup) Delete remaining route tables'
ec2_vpc_route_table:
state: absent
vpc_id: '{{ vpc_id }}'
route_table_id: '{{ item.id }}'
lookup: 'id'
register: rtbs_removed
loop: '{{ remaining_rtbs.route_tables }}'
ignore_errors: yes

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

- name: '(VPC Cleanup) Remove the VPC'
ec2_vpc_net:
state: absent
vpc_id: '{{ vpc_id }}'
register: vpc_removed
until: vpc_removed is not failed
ignore_errors: yes
retries: 10
2 changes: 2 additions & 0 deletions tests/integration/targets/setup_ec2_vpc/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- debug:
msg: 'VPC Cleanup module loaded'