Skip to content

Commit

Permalink
Merge pull request #1066 from alinabuzachis/promote_route53_utils
Browse files Browse the repository at this point in the history
Promote route53 module_utils

SUMMARY

Promote route53 module_utils

ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Sep 26, 2022
2 parents 9c8cfd3 + f1b6831 commit 8183000
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/migrate_route53_module_utils.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- route53 - Migrate plugins/module_utils/route53.py to amazon.aws (https://github.com/ansible-collections/amazon.aws/pull/1066).
64 changes: 64 additions & 0 deletions plugins/module_utils/route53.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file is part of Ansible
# 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:
import botocore
except ImportError:
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 compare_aws_tags


def manage_tags(module, client, resource_type, resource_id, new_tags, purge_tags):
if new_tags is None:
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)

change_params = dict()
if 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

if not change_params:
return False

if module.check_mode:
return True

try:
client.change_tags_for_resource(
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)
return True


def get_tags(module, client, resource_type, resource_id):
try:
tagset = client.list_tags_for_resource(
ResourceType=resource_type,
ResourceId=resource_id,
)
except is_boto3_error_code('NoSuchHealthCheck'):
return {}
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)

tags = boto3_tag_list_to_ansible_dict(tagset['ResourceTagSet']['Tags'])
return tags
4 changes: 2 additions & 2 deletions plugins/modules/route53_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.community.aws.plugins.module_utils.route53 import get_tags
from ansible_collections.community.aws.plugins.module_utils.route53 import manage_tags
from ansible_collections.amazon.aws.plugins.module_utils.route53 import get_tags
from ansible_collections.amazon.aws.plugins.module_utils.route53 import manage_tags


def _list_health_checks(**params):
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/route53_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
import time
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.community.aws.plugins.module_utils.route53 import manage_tags
from ansible_collections.community.aws.plugins.module_utils.route53 import get_tags
from ansible_collections.amazon.aws.plugins.module_utils.route53 import manage_tags
from ansible_collections.amazon.aws.plugins.module_utils.route53 import get_tags

try:
from botocore.exceptions import BotoCoreError, ClientError
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/route53/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cloud/aws

route53_info
module_utils_route53

0 comments on commit 8183000

Please sign in to comment.