Skip to content

Commit

Permalink
ec2_vpc_endpoint - fixup deletion 'changed' (ansible-collections#362)
Browse files Browse the repository at this point in the history
* Ensure ec2_vpc_endpoint returns True when deleting an Endpoint
Return not changed when state=absent and endpoint has already been deleted

* Add minimal endpoint tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@a89ec90
  • Loading branch information
tremble authored and alinabuzachis committed Aug 23, 2021
1 parent d13a24d commit 6211534
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/modules/ec2_vpc_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,16 @@ def setup_removal(client, module):
params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id')
try:
result = client.delete_vpc_endpoints(**params)['Unsuccessful']
if not module.check_mode and (result != []):
module.fail_json(msg=result)
if len(result) < len(params['VpcEndpointIds']):
changed = True
# For some reason delete_vpc_endpoints doesn't throw exceptions it
# returns a list of failed 'results' instead. Throw these so we can
# catch them the way we expect
for r in result:
try:
raise botocore.exceptions.ClientError(r, 'delete_vpc_endpoints')
except is_boto3_error_code('InvalidVpcEndpoint.NotFound'):
continue
except is_boto3_error_code('DryRunOperation'):
changed = True
result = 'Would have deleted VPC Endpoint if not in check mode'
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/ec2_vpc_endpoint/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cloud/aws
shippable/aws/group2
ec2_vpc_endpoint_info
8 changes: 8 additions & 0 deletions tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
vpc_name: '{{ resource_prefix }}-vpc'
vpc_seed: '{{ resource_prefix }}'
vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.22.0/24'

# S3 and EC2 should generally be available...
endpoint_service_a: 'com.amazonaws.{{ aws_region }}.s3'
endpoint_service_b: 'com.amazonaws.{{ aws_region }}.ec2'
Loading

0 comments on commit 6211534

Please sign in to comment.