Skip to content

Commit

Permalink
route53_health_check - add tagging support (ansible-collections#765)
Browse files Browse the repository at this point in the history
route53_health_check - add tagging support

SUMMARY
add tagging support to route53_health_check
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
route53_health_check
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@3248016
  • Loading branch information
tremble authored and goneri committed Sep 21, 2022
1 parent f1cae67 commit ee7f570
Show file tree
Hide file tree
Showing 2 changed files with 515 additions and 17 deletions.
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

0 comments on commit ee7f570

Please sign in to comment.