diff --git a/changelogs/fragments/537-ec2_vpc_endpoint_info-retries.yml b/changelogs/fragments/537-ec2_vpc_endpoint_info-retries.yml new file mode 100644 index 00000000000..fa619b76221 --- /dev/null +++ b/changelogs/fragments/537-ec2_vpc_endpoint_info-retries.yml @@ -0,0 +1,3 @@ +minor_changes: +- ec2_vpc_endpoint_info - use boto3 paginator when fetching services (https://github.com/ansible-collections/community.aws/pull/537). +- ec2_vpc_endpoint_info - ensure paginated endpoint description is retried on common AWS failures (https://github.com/ansible-collections/community.aws/pull/537). diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 425e0c63ec7..d990a908943 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -126,21 +126,28 @@ from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -@AWSRetry.exponential_backoff() +@AWSRetry.jittered_backoff() +def _describe_endpoints(client, **params): + paginator = client.get_paginator('describe_vpc_endpoints') + return paginator.paginate(**params).build_full_result() + + +@AWSRetry.jittered_backoff() +def _describe_endpoint_services(client, **params): + paginator = client.get_paginator('describe_vpc_endpoint_services') + return paginator.paginate(**params).build_full_result() + + def get_supported_services(client, module): - results = list() - params = dict() - while True: - response = client.describe_vpc_endpoint_services(**params) - results.extend(response['ServiceNames']) - if 'NextToken' in response: - params['NextToken'] = response['NextToken'] - else: - break + try: + services = _describe_endpoint_services(client) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Failed to get endpoint servicess") + + results = list(services['ServiceNames']) return dict(service_names=results) -@AWSRetry.exponential_backoff() def get_endpoints(client, module): results = list() params = dict() @@ -148,14 +155,13 @@ def get_endpoints(client, module): if module.params.get('vpc_endpoint_ids'): params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') try: - paginator = client.get_paginator('describe_vpc_endpoints') - results = paginator.paginate(**params).build_full_result()['VpcEndpoints'] - + results = _describe_endpoints(client, **params)['VpcEndpoints'] results = normalize_boto3_result(results) except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[]) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Failed to get endpoints") + return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml index daa2a103624..0bd2beed8c5 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -536,6 +536,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -547,7 +548,8 @@ assert: that: - tag_vpc_endpoint.changed - - tag_vpc_endpoint.result.tags | length == 5 + - tag_vpc_endpoint.result.tags | length == 6 + - endpoint_tags["testPrefix"] == resource_prefix - endpoint_tags["camelCase"] == "helloWorld" - endpoint_tags["PascalCase"] == "HelloWorld" - endpoint_tags["snake_case"] == "hello_world" @@ -560,8 +562,8 @@ ec2_vpc_endpoint_info: query: endpoints filters: - "tag:camelCase": - - "helloWorld" + "tag:testPrefix": + - "{{ resource_prefix }}" register: tag_result - name: Assert tag lookup found endpoint @@ -582,6 +584,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -603,6 +606,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -649,7 +653,8 @@ assert: that: - add_tag_vpc_endpoint.changed - - add_tag_vpc_endpoint.result.tags | length == 6 + - add_tag_vpc_endpoint.result.tags | length == 7 + - endpoint_tags["testPrefix"] == resource_prefix - endpoint_tags["camelCase"] == "helloWorld" - endpoint_tags["PascalCase"] == "HelloWorld" - endpoint_tags["snake_case"] == "hello_world"