-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #565 from badnetmask/route53_tags
Implement tags support for AWS Route 53 objects SUMMARY Implement tags support for AWS Route 53 objects. ISSUE TYPE Feature Pull Request COMPONENT NAME community.aws.route53 community.aws.route53_health_check ADDITIONAL INFORMATION Current AWS Route 53 modules does not support tagging objects. This is important for organization, ownership tracking and financial accounting on enterprise environments. - name: Create zone example.com community.aws.route53_zone: zone: example.com tags: Owner: DevOps Team purge_tags: True - name: Create www health check community.aws.route53_health_check: fqdn: www.example.com type: TCP port: 443 tags: Owner: DevOps Team purge_tags: True Reviewed-by: Jill R <None> Reviewed-by: Markus Bergholz <git@osuv.de> Reviewed-by: Mauricio Teixeira <None> Reviewed-by: Mark Chappell <None> Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
- Loading branch information
Showing
5 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- route53_zone - add support for tagging Route 53 zones (https://github.com/ansible-collections/community.aws/pull/565). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# 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): | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters