Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix idempotency and logic to update existing aggregator #645

Merged
merged 5 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- aws_config_aggregator - Fix idempotency when ``account_sources`` parameter is not specified (https://github.com/ansible-collections/community.aws/pull/645).
- aws_config_aggregator - Fix `KeyError` when updating existing aggregator (https://github.com/ansible-collections/community.aws/pull/645).
15 changes: 9 additions & 6 deletions plugins/modules/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
72 changes: 72 additions & 0 deletions tests/integration/targets/aws_config/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@
that:
- output.changed

- name: Create aws_config_aggregator
aws_config_aggregator:
name: random_name
state: present
account_sources: []
organization_source:
all_aws_regions: true
role_arn: "{{ config_iam_role.arn }}"
register: output

- name: assert success
assert:
that:
- output is changed

- name: Create aws_config_aggregator - idempotency
aws_config_aggregator:
name: random_name
state: present
account_sources: []
organization_source:
all_aws_regions: true
role_arn: "{{ config_iam_role.arn }}"
register: output

- name: assert not changed
assert:
that:
- output is not changed

# ============================================================
# Update testing
# ============================================================
Expand Down Expand Up @@ -250,6 +280,40 @@
that:
- output.changed

- name: Update aws_config_aggregator
aws_config_aggregator:
name: random_name
state: present
account_sources: []
organization_source:
all_aws_regions: false
aws_regions:
- '{{ aws_region }}'
role_arn: "{{ config_iam_role.arn }}"
register: output

- name: assert success
assert:
that:
- output is changed

- name: Update aws_config_aggregator - idempotency
aws_config_aggregator:
name: random_name
state: present
account_sources: []
organization_source:
all_aws_regions: false
aws_regions:
- '{{ aws_region }}'
role_arn: "{{ config_iam_role.arn }}"
register: output

- name: assert success
assert:
that:
- output is not changed

# ============================================================
# Read testing
# ============================================================
Expand Down Expand Up @@ -300,6 +364,14 @@
- not output.changed

always:

- name: delete aws_config_aggregator
aws_config_aggregator:
name: random_name
state: absent
register: output
ignore_errors: true

# ============================================================
# Destroy testing
# ============================================================
Expand Down