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 goneri committed Jun 25, 2021
1 parent 41bc424 commit a5373b3
Showing 1 changed file with 10 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

0 comments on commit a5373b3

Please sign in to comment.