From 3cd745b83529808309b141d5fd247a31a8b5464a Mon Sep 17 00:00:00 2001 From: "Michael K. Haskell" Date: Thu, 27 Oct 2022 10:43:17 -0700 Subject: [PATCH] #1573 fix pep8 errors and add changelong fragment --- .../1574-ssm-parameter-support-for-tags.yml | 2 ++ plugins/modules/ssm_parameter.py | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/1574-ssm-parameter-support-for-tags.yml diff --git a/changelogs/fragments/1574-ssm-parameter-support-for-tags.yml b/changelogs/fragments/1574-ssm-parameter-support-for-tags.yml new file mode 100644 index 00000000000..6340f821972 --- /dev/null +++ b/changelogs/fragments/1574-ssm-parameter-support-for-tags.yml @@ -0,0 +1,2 @@ +minor_changes: + - ssm_parameter - add support for tags in ssm parameters (https://github.com/ansible-collections/community.aws/issues/1573). \ No newline at end of file diff --git a/plugins/modules/ssm_parameter.py b/plugins/modules/ssm_parameter.py index 918e96460bb..3d5e4b78639 100644 --- a/plugins/modules/ssm_parameter.py +++ b/plugins/modules/ssm_parameter.py @@ -351,51 +351,55 @@ def _wait_deleted(client, module, name): def tag_parameter(client, module, parameter_name, tags): try: return client.add_tags_to_resource(aws_retry=True, ResourceType='Parameter', - ResourceId=parameter_name, Tags=tags) + ResourceId=parameter_name, Tags=tags) except (BotoCoreError, ClientError) as e: module.fail_json_aws(e, msg="Failed to add tag(s) to parameter") + def untag_parameter(client, module, parameter_name, tag_keys): try: - return client.remove_tags_from_resource(aws_retry=True, ResourceType='Parameter', - ResourceId=parameter_name, TagKeys=tag_keys) + return client.remove_tags_from_resource(aws_retry=True, ResourceType='Parameter', + ResourceId=parameter_name, TagKeys=tag_keys) except (BotoCoreError, ClientError) as e: module.fail_json_aws(e, msg="Failed to remove tag(s) from parameter") + def get_parameter_tags(client, module, parameter_name): try: - tags = client.list_tags_for_resource(aws_retry=True, ResourceType='Parameter', - ResourceId=parameter_name)['TagList'] + tags = client.list_tags_for_resource(aws_retry=True, ResourceType='Parameter', + ResourceId=parameter_name)['TagList'] tags_dict = boto3_tag_list_to_ansible_dict(tags) return tags_dict, tags except (BotoCoreError, ClientError) as e: module.fail_json_aws(e, msg="Unable to retrieve parameter tags") + def update_parameter_tags(client, module, parameter_name, supplied_tags): changed = False response = {} - + if supplied_tags is None: return False, response current_tags, _ = get_parameter_tags(client, module, parameter_name) - tags_to_add, tags_to_remove = compare_aws_tags(current_tags, supplied_tags, - module.params.get('purge_tags')) - + tags_to_add, tags_to_remove = compare_aws_tags(current_tags, supplied_tags, + module.params.get('purge_tags')) + if tags_to_add: if module.check_mode: return True, response response = tag_parameter(client, module, parameter_name, - ansible_dict_to_boto3_tag_list(tags_to_add)) + ansible_dict_to_boto3_tag_list(tags_to_add)) changed = True if tags_to_remove: if module.check_mode: return True, response response = untag_parameter(client, module, parameter_name, tags_to_remove) changed = True - + return changed, response + def update_parameter(client, module, **args): changed = False response = {} @@ -489,14 +493,14 @@ def create_update_parameter(client, module): # import time # time.sleep(300) - # Handle tag updates for existing parameters + # Handle tag updates for existing parameters if (module.params.get('overwrite_value') != 'never'): - tags_changed, tags_response = update_parameter_tags(client, module, + tags_changed, tags_response = update_parameter_tags(client, module, existing_parameter['Parameter']['Name'], module.params.get('tags')) changed = changed or tags_changed - if tags_response: + if tags_response: response['tag_updates'] = tags_response