From 09dfde7e29ae0995cb77867f0f3db916c62fa097 Mon Sep 17 00:00:00 2001 From: ichekaldin <39010411+ichekaldin@users.noreply.github.com> Date: Wed, 21 Apr 2021 19:04:31 +0000 Subject: [PATCH] Fix KeyError in aws_config_aggregator module If `organization_source` attribute is specified, module fails with the following error on line 206: ``` KeyError: 'OrganizationAggregationSourcep' ``` If `organization_source` attribute is specified and `account_sources` attribute is empty, module fails with the following error on line 119: ``` KeyError: 'AccountAggregationSources' ``` This PR fixes both issues. --- .../553-aws_config_aggregator-fix-organization-source.yml | 2 ++ plugins/modules/aws_config_aggregator.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/553-aws_config_aggregator-fix-organization-source.yml diff --git a/changelogs/fragments/553-aws_config_aggregator-fix-organization-source.yml b/changelogs/fragments/553-aws_config_aggregator-fix-organization-source.yml new file mode 100644 index 00000000000..2b020f50b76 --- /dev/null +++ b/changelogs/fragments/553-aws_config_aggregator-fix-organization-source.yml @@ -0,0 +1,2 @@ +minor_changes: + - aws_config_aggregator - Fix typos in attribute names (https://github.com/ansible-collections/community.aws/pull/553). diff --git a/plugins/modules/aws_config_aggregator.py b/plugins/modules/aws_config_aggregator.py index 250f004a0f7..16f6ff5152a 100644 --- a/plugins/modules/aws_config_aggregator.py +++ b/plugins/modules/aws_config_aggregator.py @@ -103,7 +103,7 @@ def resource_exists(client, module, params): try: aggregator = client.describe_configuration_aggregators( - ConfigurationAggregatorNames=[params['name']] + ConfigurationAggregatorNames=[params['ConfigurationAggregatorName']] ) return aggregator['ConfigurationAggregators'][0] except is_boto3_error_code('NoSuchConfigurationAggregatorException'): @@ -128,7 +128,7 @@ def create_resource(client, module, params, result): def update_resource(client, module, params, result): current_params = client.describe_configuration_aggregators( - ConfigurationAggregatorNames=[params['name']] + ConfigurationAggregatorNames=[params['ConfigurationAggregatorName']] ) del current_params['ConfigurationAggregatorArn'] @@ -181,8 +181,8 @@ def main(): params = {} if name: params['ConfigurationAggregatorName'] = name + params['AccountAggregationSources'] = [] if module.params.get('account_sources'): - params['AccountAggregationSources'] = [] for i in module.params.get('account_sources'): tmp_dict = {} if i.get('account_ids'): @@ -203,7 +203,7 @@ def main(): 'AwsRegions': module.params.get('organization_source').get('aws_regions') }) if module.params.get('organization_source').get('all_aws_regions') is not None: - params['OrganizationAggregationSourcep'].update({ + params['OrganizationAggregationSource'].update({ 'AllAwsRegions': module.params.get('organization_source').get('all_aws_regions') })