Skip to content

Commit

Permalink
Fix idempotency and logic to update existing aggregator (ansible-coll…
Browse files Browse the repository at this point in the history
…ections#645)

Fix idempotency and logic to update existing aggregator

SUMMARY

describe_configuration_aggregators method returns output similar
to the following:
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].
The error message is:
KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

aws_config_aggregator
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
  • Loading branch information
ichekaldin authored Jul 2, 2022
1 parent 19e2358 commit ee3263d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions aws_config_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,25 @@ def create_resource(client, module, params, result):


def update_resource(client, module, params, result):
result['changed'] = False

current_params = client.describe_configuration_aggregators(
ConfigurationAggregatorNames=[params['ConfigurationAggregatorName']]
)
)['ConfigurationAggregators'][0]

del current_params['ConfigurationAggregatorArn']
del current_params['CreationTime']
del current_params['LastUpdatedTime']
if params['AccountAggregationSources'] != current_params.get('AccountAggregationSources', []):
result['changed'] = True

if params['OrganizationAggregationSource'] != current_params.get('OrganizationAggregationSource', {}):
result['changed'] = True

if params != current_params['ConfigurationAggregators'][0]:
if result['changed']:
try:
client.put_configuration_aggregator(
ConfigurationAggregatorName=params['ConfigurationAggregatorName'],
AccountAggregationSources=params['AccountAggregationSources'],
OrganizationAggregationSource=params['OrganizationAggregationSource']
)
result['changed'] = True
result['aggregator'] = camel_dict_to_snake_dict(resource_exists(client, module, params))
return result
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
Expand Down

0 comments on commit ee3263d

Please sign in to comment.