Skip to content

Commit dad0431

Browse files
tremblealinabuzachis
authored andcommitted
ec2_vpc_endpoint - fixup deletion 'changed' (ansible-collections#362)
* 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
1 parent a164650 commit dad0431

File tree

4 files changed

+416
-2
lines changed

4 files changed

+416
-2
lines changed

plugins/modules/ec2_vpc_endpoint.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,16 @@ def setup_removal(client, module):
313313
params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id')
314314
try:
315315
result = client.delete_vpc_endpoints(**params)['Unsuccessful']
316-
if not module.check_mode and (result != []):
317-
module.fail_json(msg=result)
316+
if len(result) < len(params['VpcEndpointIds']):
317+
changed = True
318+
# For some reason delete_vpc_endpoints doesn't throw exceptions it
319+
# returns a list of failed 'results' instead. Throw these so we can
320+
# catch them the way we expect
321+
for r in result:
322+
try:
323+
raise botocore.exceptions.ClientError(r, 'delete_vpc_endpoints')
324+
except is_boto3_error_code('InvalidVpcEndpoint.NotFound'):
325+
continue
318326
except is_boto3_error_code('DryRunOperation'):
319327
changed = True
320328
result = 'Would have deleted VPC Endpoint if not in check mode'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cloud/aws
2+
shippable/aws/group2
3+
ec2_vpc_endpoint_info
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
vpc_name: '{{ resource_prefix }}-vpc'
3+
vpc_seed: '{{ resource_prefix }}'
4+
vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.22.0/24'
5+
6+
# S3 and EC2 should generally be available...
7+
endpoint_service_a: 'com.amazonaws.{{ aws_region }}.s3'
8+
endpoint_service_b: 'com.amazonaws.{{ aws_region }}.ec2'

0 commit comments

Comments
 (0)