forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elb_target_group - support target_type alb (ansible-collections#966)
elb_target_group - support target_type alb SUMMARY Add support for target_type alb and integration tests Update documentation for clarity Fixes ansible-collections#891 ISSUE TYPE Feature Pull Request COMPONENT NAME elb_target_group Reviewed-by: Mark Woolley <[email protected]> Reviewed-by: Mandar Kulkarni <[email protected]> Reviewed-by: Alina Buzachis <None> Reviewed-by: Markus Bergholz <[email protected]>
- Loading branch information
1 parent
1ca997a
commit 86741fe
Showing
5 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/966-elb_target_group-support-alb-target.yml
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: | ||
- elb_target_group - add support for alb target_type and update documentation (https://github.com/ansible-collections/community.aws/pull/966). |
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
205 changes: 205 additions & 0 deletions
205
tests/integration/targets/elb_target/tasks/alb_target.yml
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,205 @@ | ||
--- | ||
- name: test elb_target_group with target_type = alb | ||
block: | ||
- name: set up testing VPC | ||
ec2_vpc_net: | ||
name: "{{ resource_prefix }}-vpc" | ||
state: present | ||
cidr_block: 20.0.0.0/16 | ||
tags: | ||
Name: "{{ resource_prefix }}-vpc" | ||
Description: "Created by ansible-test" | ||
register: vpc | ||
|
||
- name: set up testing internet gateway | ||
ec2_vpc_igw: | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
state: present | ||
register: igw | ||
|
||
- name: set up testing subnet | ||
ec2_vpc_subnet: | ||
state: present | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
cidr: 20.0.0.0/18 | ||
az: "{{ aws_region }}a" | ||
resource_tags: | ||
Name: "{{ resource_prefix }}-subnet" | ||
register: subnet_1 | ||
|
||
- name: set up testing subnet | ||
ec2_vpc_subnet: | ||
state: present | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
cidr: 20.0.64.0/18 | ||
az: "{{ aws_region }}b" | ||
resource_tags: | ||
Name: "{{ resource_prefix }}-subnet" | ||
register: subnet_2 | ||
|
||
- name: create routing rules | ||
ec2_vpc_route_table: | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
tags: | ||
created: "{{ resource_prefix }}-route" | ||
routes: | ||
- dest: 0.0.0.0/0 | ||
gateway_id: "{{ igw.gateway_id }}" | ||
subnets: | ||
- "{{ subnet_1.subnet.id }}" | ||
- "{{ subnet_2.subnet.id }}" | ||
register: route_table | ||
|
||
- name: create testing security group | ||
ec2_group: | ||
name: "{{ resource_prefix }}-sg" | ||
description: a security group for ansible tests | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
rules: | ||
- proto: tcp | ||
from_port: 80 | ||
to_port: 80 | ||
cidr_ip: 0.0.0.0/0 | ||
- proto: tcp | ||
from_port: 22 | ||
to_port: 22 | ||
cidr_ip: 0.0.0.0/0 | ||
register: sg | ||
|
||
- name: set up testing target group for NLB (type=alb) | ||
elb_target_group: | ||
name: "{{ elb_target_group_name }}" | ||
target_type: alb | ||
state: present | ||
protocol: TCP | ||
port: 80 | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
register: elb_target_group | ||
|
||
- name: assert target group was created successfully | ||
assert: | ||
that: | ||
- elb_target_group.changed | ||
- elb_target_group.target_group_name == elb_target_group_name | ||
- elb_target_group.target_type == 'alb' | ||
- elb_target_group.vpc_id == vpc.vpc.id | ||
- elb_target_group.port == 80 | ||
- elb_target_group.protocol == 'TCP' | ||
- elb_target_group.load_balancer_arns | length == 0 | ||
|
||
- name: create a network load balancer and attach to target group | ||
elb_network_lb: | ||
name: "{{ lb_name }}-nlb" | ||
subnets: | ||
- "{{ subnet_1.subnet.id }}" | ||
- "{{ subnet_2.subnet.id }}" | ||
listeners: | ||
- Protocol: TCP | ||
Port: 80 | ||
DefaultActions: | ||
- Type: forward | ||
TargetGroupName: "{{ elb_target_group_name }}" | ||
state: present | ||
register: nlb | ||
|
||
- name: assert NLB was created successfully and attached to target group | ||
assert: | ||
that: | ||
- nlb is changed | ||
- nlb.listeners | length == 1 | ||
- nlb.listeners[0].default_actions[0].forward_config.target_groups[0].target_group_arn == elb_target_group.target_group_arn | ||
|
||
- name: get target group info | ||
elb_target_group_info: | ||
load_balancer_arn: "{{ nlb.load_balancer_arn }}" | ||
register: tg_info | ||
|
||
- name: assert target group's target is nlb | ||
assert: | ||
that: | ||
- tg_info.target_groups[0].target_group_name == elb_target_group_name | ||
- tg_info.target_groups[0].target_type == 'alb' | ||
- tg_info.target_groups[0].load_balancer_arns | length == 1 | ||
- tg_info.target_groups[0].load_balancer_arns[0] == nlb.load_balancer_arn | ||
|
||
always: | ||
- name: remove network load balancer | ||
elb_network_lb: | ||
name: "{{ lb_name }}-nlb" | ||
state: absent | ||
wait: true | ||
wait_timeout: 600 | ||
register: removed | ||
retries: 10 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove elb target group | ||
elb_target_group: | ||
name: "{{ elb_target_group_name }}" | ||
target_type: alb | ||
state: absent | ||
protocol: HTTP | ||
port: 80 | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
ignore_errors: true | ||
|
||
- name: remove routing rules | ||
ec2_vpc_route_table: | ||
state: absent | ||
lookup: id | ||
route_table_id: "{{ route_table.route_table.id }}" | ||
register: removed | ||
retries: 5 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove testing subnet | ||
ec2_vpc_subnet: | ||
state: absent | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
cidr: 20.0.0.0/18 | ||
az: "{{ aws_region }}a" | ||
register: removed | ||
retries: 10 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove testing subnet | ||
ec2_vpc_subnet: | ||
state: absent | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
cidr: 20.0.64.0/18 | ||
az: "{{ aws_region }}b" | ||
register: removed | ||
retries: 10 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove testing security group | ||
ec2_group: | ||
state: absent | ||
name: "{{ resource_prefix }}-sg" | ||
register: removed | ||
retries: 10 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove testing internet gateway | ||
ec2_vpc_igw: | ||
vpc_id: "{{ vpc.vpc.id }}" | ||
state: absent | ||
register: removed | ||
retries: 2 | ||
until: removed is not failed | ||
ignore_errors: true | ||
|
||
- name: remove testing VPC | ||
ec2_vpc_net: | ||
name: "{{ resource_prefix }}-vpc" | ||
cidr_block: 20.0.0.0/16 | ||
state: absent | ||
register: removed | ||
retries: 2 | ||
until: removed is not failed | ||
ignore_errors: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
block: | ||
- include_tasks: ec2_target.yml | ||
- include_tasks: lambda_target.yml | ||
- include_tasks: alb_target.yml |