[cloud] Add support for using IP addresses in target groups (#34266)

* Add support for IP based ELB target groups. Fixes #30962

* Add support for using IP addresses in target groups
This commit is contained in:
Rob 2018-01-23 08:47:41 +11:00 committed by Ryan Brown
parent de60328d94
commit 866239e01a

View file

@ -13,10 +13,11 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: elb_target_group module: elb_target_group
short_description: Manage a target group for an Application load balancer short_description: Manage a target group for an Application or Network load balancer
description: description:
- Manage an AWS Application Elastic Load Balancer target group. See - Manage an AWS Elastic Load Balancer target group. See
U(http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html) for details. U(http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html) or
U(http://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html) for details.
version_added: "2.4" version_added: "2.4"
requirements: [ boto3 ] requirements: [ boto3 ]
author: "Rob White (@wimnat)" author: "Rob White (@wimnat)"
@ -97,14 +98,25 @@ options:
default: lb_cookie default: lb_cookie
successful_response_codes: successful_response_codes:
description: description:
- > - The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, "200,202") or a range of
The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, "200,202") or a range of
values (for example, "200-299"). values (for example, "200-299").
required: false required: false
tags: tags:
description: description:
- A dictionary of one or more tags to assign to the target group. - A dictionary of one or more tags to assign to the target group.
required: false required: false
target_type:
description:
- The type of target that you must specify when registering targets with this target group. The possible values are
C(instance) (targets are specified by instance ID) or C(ip) (targets are specified by IP address).
Note that you can't specify targets for a target group using both instance IDs and IP addresses.
If the target type is ip, specify IP addresses from the subnets of the virtual private cloud (VPC) for the target
group, the RFC 1918 range (10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16), and the RFC 6598 range (100.64.0.0/10).
You can't specify publicly routable IP addresses.
required: false
default: instance
choices: ['instance', 'ip']
version_added: 2.5
targets: targets:
description: description:
- A list of targets to assign to the target group. This parameter defaults to an empty list. Unless you set the 'modify_targets' parameter then - A list of targets to assign to the target group. This parameter defaults to an empty list. Unless you set the 'modify_targets' parameter then
@ -151,22 +163,42 @@ EXAMPLES = '''
name: mytargetgroup name: mytargetgroup
state: absent state: absent
# Create a target group with targets # Create a target group with instance targets
- elb_target_group: - elb_target_group:
name: mytargetgroup name: mytargetgroup
protocol: http protocol: http
port: 81 port: 81
vpc_id: vpc-01234567 vpc_id: vpc-01234567
health_check_path: / health_check_path: /
successful_response_codes: "200,250-260" successful_response_codes: "200,250-260"
targets: targets:
- Id: i-01234567 - Id: i-01234567
Port: 80 Port: 80
- Id: i-98765432 - Id: i-98765432
Port: 80 Port: 80
state: present state: present
wait_timeout: 200 wait_timeout: 200
wait: True wait: True
# Create a target group with IP address targets
- elb_target_group:
name: mytargetgroup
protocol: http
port: 81
vpc_id: vpc-01234567
health_check_path: /
successful_response_codes: "200,250-260"
target_type: ip
targets:
- Id: 10.0.0.10
Port: 80
AvailabilityZone: all
- Id: 10.0.0.20
Port: 80
state: present
wait_timeout: 200
wait: True
''' '''
RETURN = ''' RETURN = '''
@ -380,6 +412,10 @@ def create_or_update_target_group(connection, module):
params['Matcher'] = {} params['Matcher'] = {}
params['Matcher']['HttpCode'] = module.params.get("successful_response_codes") params['Matcher']['HttpCode'] = module.params.get("successful_response_codes")
# Get target type
if module.params.get("target_type") is not None:
params['TargetType'] = module.params.get("target_type")
# Get target group # Get target group
tg = get_target_group(connection, module) tg = get_target_group(connection, module)
@ -645,6 +681,7 @@ def main():
state=dict(required=True, choices=['present', 'absent'], type='str'), state=dict(required=True, choices=['present', 'absent'], type='str'),
successful_response_codes=dict(type='str'), successful_response_codes=dict(type='str'),
tags=dict(default={}, type='dict'), tags=dict(default={}, type='dict'),
target_type=dict(type='str', default='instance', choices=['instance', 'ip']),
targets=dict(type='list'), targets=dict(type='list'),
unhealthy_threshold_count=dict(type='int'), unhealthy_threshold_count=dict(type='int'),
vpc_id=dict(type='str'), vpc_id=dict(type='str'),