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

DNM - TEST SF #841

Closed
wants to merge 1 commit into from
Closed
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
47 changes: 31 additions & 16 deletions plugins/module_utils/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type

try:
Expand All @@ -10,8 +11,12 @@
pass # caught by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.tagging import (
ansible_dict_to_boto3_tag_list,
)
from ansible_collections.amazon.aws.plugins.module_utils.tagging import (
boto3_tag_list_to_ansible_dict,
)
from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags


Expand All @@ -20,13 +25,15 @@ def manage_tags(module, client, resource_type, resource_id, new_tags, purge_tags
return False

old_tags = get_tags(module, client, resource_type, resource_id)
tags_to_set, tags_to_delete = compare_aws_tags(old_tags, new_tags, purge_tags=purge_tags)
tags_to_set, tags_to_delete = compare_aws_tags(
old_tags, new_tags, purge_tags=purge_tags
)

change_params = dict()
if tags_to_set:
change_params['AddTags'] = ansible_dict_to_boto3_tag_list(tags_to_set)
change_params["AddTags"] = ansible_dict_to_boto3_tag_list(tags_to_set)
if tags_to_delete:
change_params['RemoveTagKeys'] = tags_to_delete
change_params["RemoveTagKeys"] = tags_to_delete

if not change_params:
return False
Expand All @@ -36,13 +43,15 @@ def manage_tags(module, client, resource_type, resource_id, new_tags, purge_tags

try:
client.change_tags_for_resource(
ResourceType=resource_type,
ResourceId=resource_id,
**change_params
ResourceType=resource_type, ResourceId=resource_id, **change_params
)
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
module.fail_json_aws(e, msg='Failed to update tags on {0}'.format(resource_type),
resource_id=resource_id, change_params=change_params)
module.fail_json_aws(
e,
msg="Failed to update tags on {0}".format(resource_type),
resource_id=resource_id,
change_params=change_params,
)
return True


Expand All @@ -52,13 +61,19 @@ def get_tags(module, client, resource_type, resource_id):
ResourceType=resource_type,
ResourceId=resource_id,
)
except is_boto3_error_code('NoSuchHealthCheck'):
except is_boto3_error_code("NoSuchHealthCheck"):
return {}
except is_boto3_error_code('NoSuchHostedZone'): # pylint: disable=duplicate-except
except is_boto3_error_code("NoSuchHostedZone"): # pylint: disable=duplicate-except
return {}
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, msg='Failed to fetch tags on {0}'.format(resource_type),
resource_id=resource_id)
except (
botocore.exceptions.BotoCoreError,
botocore.exceptions.ClientError,
) as e: # pylint: disable=duplicate-except
module.fail_json_aws(
e,
msg="Failed to fetch tags on {0}".format(resource_type),
resource_id=resource_id,
)

tags = boto3_tag_list_to_ansible_dict(tagset['ResourceTagSet']['Tags'])
tags = boto3_tag_list_to_ansible_dict(tagset["ResourceTagSet"]["Tags"])
return tags