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

route53_health_check - add tagging support #765

Merged
merged 1 commit into from
Oct 18, 2021
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
2 changes: 2 additions & 0 deletions changelogs/fragments/765-route53_health_check-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- route53_health_check - add support for tagging health checks (https://github.com/ansible-collections/community.aws/pull/765).
3 changes: 3 additions & 0 deletions plugins/module_utils/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@


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)

Expand Down
28 changes: 27 additions & 1 deletion plugins/modules/route53_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
- Will default to C(3) if not specified on creation.
choices: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
type: int
tags:
description:
- A hash/dictionary of tags to set on the health check.
type: dict
version_added: 2.1.0
purge_tags:
description:
- Delete any tags not specified in I(tags).
default: false
type: bool
version_added: 2.1.0
author: "zimbatm (@zimbatm)"
extends_documentation_fragment:
- amazon.aws.aws
Expand Down Expand Up @@ -198,6 +209,11 @@
type: bool
returned: When the health check exists.
sample: false
tags:
description: A dictionary representing the tags on the health check.
type: dict
returned: When the health check exists.
sample: '{"my_key": "my_value"}'
'''

import uuid
Expand All @@ -212,6 +228,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


def _list_health_checks(**params):
Expand Down Expand Up @@ -332,7 +350,8 @@ def create_health_check(ip_addr_in, fqdn_in, type_in, request_interval_in, port_
except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
module.fail_json_aws(e, msg='Failed to create health check.', health_check=health_check)

return True, 'create', result.get('HealthCheck').get('Id')
check_id = result.get('HealthCheck').get('Id')
return True, 'create', check_id


def update_health_check(existing_check):
Expand Down Expand Up @@ -396,6 +415,8 @@ def describe_health_check(id):

health_check = result.get('HealthCheck', {})
health_check = camel_dict_to_snake_dict(health_check)
tags = get_tags(module, client, 'healthcheck', id)
health_check['tags'] = tags
return health_check


Expand All @@ -411,6 +432,8 @@ def main():
string_match=dict(),
request_interval=dict(type='int', choices=[10, 30], default=30),
failure_threshold=dict(type='int', choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
tags=dict(type='dict'),
purge_tags=dict(type='bool', default=False),
)

args_one_of = [
Expand Down Expand Up @@ -473,6 +496,9 @@ def main():
changed, action, check_id = create_health_check(ip_addr_in, fqdn_in, type_in, request_interval_in, port_in)
else:
changed, action = update_health_check(existing_check)
if check_id:
changed |= manage_tags(module, client, 'healthcheck', check_id,
module.params.get('tags'), module.params.get('purge_tags'))

health_check = describe_health_check(id=check_id)
health_check['action'] = action
Expand Down
Loading