Skip to content

Commit

Permalink
elb_instance - boto3 migration (ansible-collections#773)
Browse files Browse the repository at this point in the history
elb_instance - boto3 migration

SUMMARY
Migrate elb_instance to boto3
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
elb_instance
ADDITIONAL INFORMATION
Depends-On: ansible/ansible-zuul-jobs#1200

Reviewed-by: Jill R <None>
Reviewed-by: Mark Chappell <None>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
tremble authored Oct 27, 2021
1 parent 1c1fae3 commit 96f1518
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 203 deletions.
7 changes: 7 additions & 0 deletions changelogs/fragments/773-elb_instance-boto3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
minor_changes:
- elb_instance - the module has been migrated to the boto3 AWS SDK (https://github.com/ansible-collections/community.aws/pull/773).
- elb_instance - added new ``updated_elbs`` return value (https://github.com/ansible-collections/community.aws/pull/773).
deprecated_features:
- elb_instance - setting of the ``ec2_elb`` fact has been deprecated and will be removed in release 4.0.0 of the collection.
See the module documentation for an alternative example using the register keyword
(https://github.com/ansible-collections/community.aws/pull/773).
365 changes: 197 additions & 168 deletions plugins/modules/elb_instance.py

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion tests/integration/targets/elb_instance/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
---
# defaults file for ec2_elb_lb
# defaults file for elb_instance

elb_name_1: 'ansible-test-{{ tiny_prefix }}-1'
elb_name_2: 'ansible-test-{{ tiny_prefix }}-2'

vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16'
subnet_cidr_1: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24'
subnet_cidr_2: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24'

instance_name_1: 'ansible-test-{{ tiny_prefix }}-elb-instance-1'
instance_name_2: 'ansible-test-{{ tiny_prefix }}-elb-instance-2'
lc_name: 'ansible-test-{{ tiny_prefix }}-elb-instance'
asg_name: 'ansible-test-{{ tiny_prefix }}-elb-instance'
vpc_name: 'ansible-test-{{ tiny_prefix }}-elb-instance'
subnet_name_1: 'ansible-test-{{ tiny_prefix }}-elb-instance-1'
subnet_name_2: 'ansible-test-{{ tiny_prefix }}-elb-instance-2'
sg_name_1: 'ansible-test-{{ tiny_prefix }}-elb-instance-1'
sg_name_2: 'ansible-test-{{ tiny_prefix }}-elb-instance-2'

availability_zone_a: '{{ ec2_availability_zone_names[0] }}'
availability_zone_b: '{{ ec2_availability_zone_names[1] }}'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

- name: Delete ASG
ec2_asg:
name: "ansible-test-{{ tiny_prefix }}-elb"
name: '{{ asg_name }}'
state: absent
ignore_errors: true
register: ec2_asg_a

- name: Delete Launch Template
ec2_lc:
name: "ansible-test-{{ tiny_prefix }}-elb"
name: '{{ lc_name }}'
state: absent
ignore_errors: true
register: ec2_lc_a
6 changes: 3 additions & 3 deletions tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
state: absent
ignore_errors: true
loop:
- '{{ resource_prefix }}-a'
- '{{ resource_prefix }}-b'
- '{{ sg_name_1 }}'
- '{{ sg_name_2 }}'

- name: delete subnets
ec2_vpc_subnet:
Expand All @@ -22,5 +22,5 @@
ec2_vpc_net:
cidr_block: '{{ vpc_cidr }}'
state: absent
name: '{{ resource_prefix }}'
name: '{{ vpc_name }}'
ignore_errors: true
19 changes: 15 additions & 4 deletions tests/integration/targets/elb_instance/tasks/manage_asgs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Get ASG info
ec2_asg_info:
name: "ansible-test-{{ tiny_prefix }}-elb$"
name: "{{ asg_name }}$"
register: asg_info

- name: Store Instance ID from ASG
Expand All @@ -26,7 +26,10 @@
- assert:
that:
- remove_instance is successful
# - remove_instance is changed
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
Expand Down Expand Up @@ -54,6 +57,9 @@
that:
- remove_instance is successful
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
Expand Down Expand Up @@ -82,6 +88,9 @@
that:
- remove_instance is successful
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state
- instance_asg not in elb_info_1.elbs[0].instances_inservice
- instance_asg not in elb_info_2.elbs[0].instances_inservice
Expand All @@ -103,8 +112,10 @@
- assert:
that:
- remove_instance is successful
# XXX always returns the ELBs the ASG belongs to
# - remove_instance is not changed
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state
- instance_asg not in elb_info_1.elbs[0].instances_inservice
- instance_asg not in elb_info_2.elbs[0].instances_inservice
167 changes: 163 additions & 4 deletions tests/integration/targets/elb_instance/tasks/manage_instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
- assert:
that:
- add_instance is successful
# - add_instance is changed
- add_instance is changed
- '"updated_elbs" in add_instance'
- elb_name_1 in add_instance.updated_elbs
- elb_name_2 in add_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in add_instance'
- '"ec2_elbs" in add_instance.ansible_facts'
Expand Down Expand Up @@ -58,6 +61,9 @@
that:
- add_instance is successful
- add_instance is changed
- '"updated_elbs" in add_instance'
- elb_name_1 in add_instance.updated_elbs
- elb_name_2 in add_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in add_instance'
- '"ec2_elbs" in add_instance.ansible_facts'
Expand Down Expand Up @@ -89,6 +95,9 @@
that:
- add_instance is successful
- add_instance is not changed
- '"updated_elbs" in add_instance'
- elb_name_1 not in add_instance.updated_elbs
- elb_name_2 not in add_instance.updated_elbs
# Check the real state didn't change
- instance_a in elb_info_1.elbs[0].instances_inservice
- instance_a in elb_info_2.elbs[0].instances_inservice
Expand All @@ -114,6 +123,9 @@
that:
- add_instance is successful
- add_instance is not changed
- '"updated_elbs" in add_instance'
- elb_name_1 not in add_instance.updated_elbs
- elb_name_2 not in add_instance.updated_elbs
# Check the real state didn't change
- instance_a in elb_info_1.elbs[0].instances_inservice
- instance_a in elb_info_2.elbs[0].instances_inservice
Expand All @@ -137,7 +149,7 @@

- assert:
that:
# - add_instance is failed
# - add_instance is failed
# Check the real state didn't change
- instance_b not in elb_info_1.elbs[0].instances_inservice

Expand Down Expand Up @@ -243,7 +255,6 @@
#
################################################################################


- name: 'Remove an instance from two ELBs (check_mode)'
elb_instance:
instance_id: '{{ instance_a }}'
Expand All @@ -265,7 +276,10 @@
- assert:
that:
- remove_instance is successful
# - remove_instance is changed
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
Expand Down Expand Up @@ -296,6 +310,9 @@
that:
- remove_instance is successful
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
Expand Down Expand Up @@ -327,6 +344,9 @@
that:
- remove_instance is successful
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state didn't change
- instance_a not in elb_info_1.elbs[0].instances_inservice
- instance_a not in elb_info_2.elbs[0].instances_inservice
Expand All @@ -352,6 +372,145 @@
that:
- remove_instance is successful
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state didn't change
- instance_a not in elb_info_1.elbs[0].instances_inservice
- instance_a not in elb_info_2.elbs[0].instances_inservice

################################################################################

- name: 'Add second instance to one ELB'
elb_instance:
instance_id: '{{ instance_b }}'
state: 'present'
ec2_elbs:
- '{{ elb_name_2 }}'
wait_timeout: 60
register: add_instance

- assert:
that:
- add_instance is successful
- add_instance is changed
- '"updated_elbs" in add_instance'
- elb_name_1 not in add_instance.updated_elbs
- elb_name_2 in add_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in add_instance'
- '"ec2_elbs" in add_instance.ansible_facts'
- elb_name_1 not in add_instance.ansible_facts.ec2_elbs
- elb_name_2 in add_instance.ansible_facts.ec2_elbs

- name: 'Remove an instance without specifying ELBs (check_mode)'
elb_instance:
instance_id: '{{ instance_b }}'
state: 'absent'
wait_timeout: 60
register: remove_instance
check_mode: true

- elb_classic_lb_info:
names: '{{ elb_name_1 }}'
register: elb_info_1
- elb_classic_lb_info:
names: '{{ elb_name_2 }}'
register: elb_info_2

- assert:
that:
- remove_instance is successful
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
- elb_name_1 not in remove_instance.ansible_facts.ec2_elbs
- elb_name_2 in remove_instance.ansible_facts.ec2_elbs
# Check the real state didn't change
- instance_b not in elb_info_1.elbs[0].instances_inservice
- instance_b in elb_info_2.elbs[0].instances_inservice

- name: 'Remove an instance without specifying ELBs'
elb_instance:
instance_id: '{{ instance_b }}'
state: 'absent'
wait_timeout: 60
register: remove_instance

- elb_classic_lb_info:
names: '{{ elb_name_1 }}'
register: elb_info_1
- elb_classic_lb_info:
names: '{{ elb_name_2 }}'
register: elb_info_2

- assert:
that:
- remove_instance is successful
- remove_instance is changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 in remove_instance.updated_elbs
# It really shouldn't be returning a fact here
- '"ansible_facts" in remove_instance'
- '"ec2_elbs" in remove_instance.ansible_facts'
- elb_name_1 not in remove_instance.ansible_facts.ec2_elbs
- elb_name_2 in remove_instance.ansible_facts.ec2_elbs
# Check the real state
- instance_b not in elb_info_1.elbs[0].instances_inservice
- instance_b not in elb_info_2.elbs[0].instances_inservice

- name: 'Remove an instance without specifying ELBs - idempotency (check_mode)'
elb_instance:
instance_id: '{{ instance_b }}'
state: 'absent'
wait_timeout: 60
register: remove_instance
check_mode: true

- elb_classic_lb_info:
names: '{{ elb_name_1 }}'
register: elb_info_1
- elb_classic_lb_info:
names: '{{ elb_name_2 }}'
register: elb_info_2

- assert:
that:
- remove_instance is successful
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state didn't change
- instance_b not in elb_info_1.elbs[0].instances_inservice
- instance_b not in elb_info_2.elbs[0].instances_inservice

- name: 'Remove an instance without specifying ELBs - idempotency'
elb_instance:
instance_id: '{{ instance_b }}'
state: 'absent'
wait_timeout: 60
register: remove_instance

- elb_classic_lb_info:
names: '{{ elb_name_1 }}'
register: elb_info_1
- elb_classic_lb_info:
names: '{{ elb_name_2 }}'
register: elb_info_2

- assert:
that:
- remove_instance is successful
- remove_instance is not changed
- '"updated_elbs" in remove_instance'
- elb_name_1 not in remove_instance.updated_elbs
- elb_name_2 not in remove_instance.updated_elbs
# Check the real state didn't change
- instance_b not in elb_info_1.elbs[0].instances_inservice
- instance_b not in elb_info_2.elbs[0].instances_inservice
10 changes: 0 additions & 10 deletions tests/integration/targets/elb_instance/tasks/setup_elbs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
timeout: 2
register: result

- assert:
that:
- result is changed
- result.elb.status == "created"

- name: Create a private load balancer with 2 AZs enabled
elb_classic_lb:
name: "{{ elb_name_2 }}"
Expand All @@ -38,8 +33,3 @@
interval: 5
timeout: 2
register: result

- assert:
that:
- result is changed
- result.elb.status == "created"
Loading

0 comments on commit 96f1518

Please sign in to comment.