From a2be6da7f4169527493ab2ec4ff061eb4d85ac7b Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 21 Dec 2021 03:40:05 -0800 Subject: [PATCH] elb_classic_lb: fix - resolve security_group_ids when providing security_group_names (#592) elb_classic_lb: fix - resolve security_group_ids when providing security_group_names SUMMARY Fix failed to resolve security_group_ids when providing security_group_names. Fix broken tasks in integration tests. Fixes #589. ISSUE TYPE Bugfix Pull Request COMPONENT NAME elb_classic_lb Reviewed-by: Mark Chappell Reviewed-by: None --- .../fragments/592-elb_classic_lb-handle-sg-ids-fix-tests.yml | 2 ++ plugins/modules/elb_classic_lb.py | 4 ++-- .../targets/elb_classic_lb/tasks/simple_instances.yml | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/592-elb_classic_lb-handle-sg-ids-fix-tests.yml diff --git a/changelogs/fragments/592-elb_classic_lb-handle-sg-ids-fix-tests.yml b/changelogs/fragments/592-elb_classic_lb-handle-sg-ids-fix-tests.yml new file mode 100644 index 00000000000..55229b1e6e3 --- /dev/null +++ b/changelogs/fragments/592-elb_classic_lb-handle-sg-ids-fix-tests.yml @@ -0,0 +1,2 @@ +bugfixes: +- elb_classic_lb - handle security_group_ids when providing security_group_names and fix broken tasks in integration test (https://github.com/ansible-collections/amazon.aws/pull/592). diff --git a/plugins/modules/elb_classic_lb.py b/plugins/modules/elb_classic_lb.py index 0f7720bd3fe..2d7913ac044 100644 --- a/plugins/modules/elb_classic_lb.py +++ b/plugins/modules/elb_classic_lb.py @@ -744,7 +744,7 @@ def __init__(self, module): if security_group_names: # Use the subnets attached to the VPC to find which VPC we're in and # limit the search - if self.elb.get('Subnets'): + if self.elb.get('Subnets', None): subnets = set(self.elb.get('Subnets') + list(self.subnets or [])) else: subnets = set(self.subnets) @@ -2042,7 +2042,7 @@ def _get_vpc_from_subnets(self, subnets): if len(vpc_ids) > 1: self.module.fail_json("Subnets for an ELB may not span multiple VPCs", subnets=subnet_details, vpc_ids=vpc_ids) - vpc_id = vpc_ids.pop() + return vpc_ids.pop() @AWSRetry.jittered_backoff() def _describe_subnets(self, subnet_ids): diff --git a/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml b/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml index a973d68dae1..8c27bc27f9f 100644 --- a/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml +++ b/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml @@ -18,6 +18,8 @@ - name: Wait for instance a ec2_instance: name: "ansible-test-{{ tiny_prefix }}-elb-a" + instance_ids: + - "{{ instance_a }}" vpc_subnet_id: "{{ subnet_a }}" instance_type: t2.micro wait: true @@ -27,6 +29,8 @@ - name: Wait for instance b ec2_instance: name: "ansible-test-{{ tiny_prefix }}-elb-b" + instance_ids: + - "{{ instance_b }}" vpc_subnet_id: "{{ subnet_b }}" instance_type: t2.micro wait: true