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
  • Loading branch information
tremble authored Feb 12, 2021
1 parent da48dc4 commit eb5168c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions 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 eb5168c

Please sign in to comment.