From 2fd7a4c73a3d3c30f4fe2f463e241cf92961aea8 Mon Sep 17 00:00:00 2001 From: Joseph Spearritt Date: Wed, 3 Aug 2022 00:03:16 +1000 Subject: [PATCH] route53_info - fix max_items when not paginating (#1384) route53_info - fix max_items when not paginating SUMMARY As reported in #1383, the route53_info module presently fails to run with a boto3 parameter validation error if run with particular combinations of parameters, specifically: query: hosted_zone parameter with hosted_zone_method: list_by_name query: reusable_delegation_set without specifying a delegation_set_id I believe this is a regression introduced in #813 ISSUE TYPE Bugfix Pull Request COMPONENT NAME route53_info ADDITIONAL INFORMATION Some further information is described in the issue but tl;dr the prior PR converted all cases in the module where params['MaxItems'] was set to instead pass a params['PaginationConfig'], however this should only be done if a boto3 paginator is actually being used, and will fail (as noted above, due to parameter validation) if called with a regular boto3 client method. Hence this PR switches back to directly setting MaxItems on the methods that do not use a paginator. Reviewed-by: Mark Chappell (cherry picked from commit 569fff4c802b226277dfee882d253821a1e1a5d9) --- .../1384-route53_info-fix-max-items.yml | 2 ++ plugins/modules/route53_info.py | 10 ++-------- tests/integration/targets/route53/tasks/main.yml | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/1384-route53_info-fix-max-items.yml diff --git a/changelogs/fragments/1384-route53_info-fix-max-items.yml b/changelogs/fragments/1384-route53_info-fix-max-items.yml new file mode 100644 index 00000000000..0b0fb1ed0bd --- /dev/null +++ b/changelogs/fragments/1384-route53_info-fix-max-items.yml @@ -0,0 +1,2 @@ +bugfixes: +- route53_info - fix ``max_items`` parameter when used with non-paginated commands (https://github.com/ansible-collections/community.aws/issues/1383). diff --git a/plugins/modules/route53_info.py b/plugins/modules/route53_info.py index 5e40efa4aad..791809fbc78 100644 --- a/plugins/modules/route53_info.py +++ b/plugins/modules/route53_info.py @@ -238,11 +238,8 @@ def reusable_delegation_set_details(): params = dict() if not module.params.get('delegation_set_id'): - # Set PaginationConfig with max_items if module.params.get('max_items'): - params['PaginationConfig'] = dict( - MaxItems=module.params.get('max_items') - ) + params['MaxItems'] = str(module.params.get('max_items')) if module.params.get('next_marker'): params['Marker'] = module.params.get('next_marker') @@ -294,11 +291,8 @@ def list_hosted_zones_by_name(): if module.params.get('dns_name'): params['DNSName'] = module.params.get('dns_name') - # Set PaginationConfig with max_items if module.params.get('max_items'): - params['PaginationConfig'] = dict( - MaxItems=module.params.get('max_items') - ) + params['MaxItems'] = str(module.params.get('max_items')) return client.list_hosted_zones_by_name(**params) diff --git a/tests/integration/targets/route53/tasks/main.yml b/tests/integration/targets/route53/tasks/main.yml index 62a82f44a31..f453a879e7c 100644 --- a/tests/integration/targets/route53/tasks/main.yml +++ b/tests/integration/targets/route53/tasks/main.yml @@ -79,6 +79,22 @@ - hosted_zones.HostedZone.ResourceRecordSetCount == 2 - hosted_zones.HostedZone.Config.PrivateZone +# Needs CI permissions updated +# # Ensure that we can use the non-paginated list_by_name method with max_items +# - name: Get zone 1 details only +# route53_info: +# query: hosted_zone +# hosted_zone_method: list_by_name +# dns_name: '{{ zone_one }}' +# max_items: 1 +# register: list_by_name_result +# +# - name: Assert that we found exactly one zone when querying by name +# assert: +# that: +# - list_by_name_result.HostedZones | length == 1 +# - list_by_name_result.HostedZones[0].Name == '{{ zone_one }}' + - name: 'Create A record using zone fqdn' route53: state: present