Repository: ansible-collections/amazon.aws

Issue:
elb_classic_lb - failed to resolve security_group_ids when providing security_group_names
### Summary

When i try to create a classic ELB it fails to resolve `security_group_ids` based on `security_group_names` & `subnets`

Locally i fixed both issues by:

1. https://github.com/ansible-collections/amazon.aws/blob/2.1.0/plugins/modules/elb_classic_lb.py#L747
    1. Change `if self.elb.get('Subnets'):` to `if self.elb is not None and self.elb.get('Subnets'):`
2. https://github.com/ansible-collections/amazon.aws/blob/2.1.0/plugins/modules/elb_classic_lb.py#L2045
    1. Change `vpc_id = vpc_ids.pop()` to `return vpc_ids.pop()`

### Issue Type

Bug Report

### Component Name

elb_classic_lb

### Ansible Version

```console (paste below)
$ ansible --version

ansible [core 2.12.0]
  config file = /Users/<USER>/Source/dataintelligence-ansible/ansible.cfg
  configured module search path = ['/Users/<USER>/Source/dataintelligence-ansible/library']
  ansible python module location = /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/<USER>/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/bin/ansible
  python version = 3.9.8 (main, Nov 18 2021, 16:08:04) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 3.0.3
  libyaml = True
```


### Collection Versions

```console (paste below)
$ ansible-galaxy collection list

# /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.1.0
ansible.netcommon             2.4.0
ansible.posix                 1.3.0
ansible.utils                 2.4.2
ansible.windows               1.8.0
arista.eos                    3.1.0
awx.awx                       19.4.0
azure.azcollection            1.10.0
check_point.mgmt              2.1.1
chocolatey.chocolatey         1.1.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.17
cisco.ios                     2.5.0
cisco.iosxr                   2.5.0
cisco.ise                     1.2.1
cisco.meraki                  2.5.0
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.7.1
cisco.ucs                     1.6.0
cloud.common                  2.1.0
cloudscale_ch.cloud           2.2.0
community.aws                 2.1.0
community.azure               1.1.0
community.ciscosmb            1.0.4
community.crypto              2.0.1
community.digitalocean        1.12.0
community.dns                 2.0.3
community.docker              2.0.1
community.fortios             1.0.0
community.general             4.0.2
community.google              1.0.0
community.grafana             1.2.3
community.hashi_vault         2.0.0
community.hrobot              1.2.1
community.kubernetes          2.0.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.1
community.network             3.0.0
community.okd                 2.1.0
community.postgresql          1.5.0
community.proxysql            1.3.0
community.rabbitmq            1.1.0
community.routeros            2.0.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.16.0
community.windows             1.8.0
community.zabbix              1.5.0
containers.podman             1.8.2
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            4.2.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.12.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.3
frr.frr                       1.0.3
gluster.gluster               1.0.2
google.cloud                  1.0.2
hetzner.hcloud                1.6.0
hpe.nimble                    1.1.3
ibm.qradar                    1.0.3
infinidat.infinibox           1.3.0
infoblox.nios_modules         1.1.2
inspur.sm                     1.3.0
junipernetworks.junos         2.6.0
kubernetes.core               2.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.0
netapp.elementsw              21.7.0
netapp.ontap                  21.13.1
netapp.storagegrid            21.7.0
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.3.0
ngine_io.cloudstack           2.2.2
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.3
openvswitch.openvswitch       2.0.2
ovirt.ovirt                   1.6.5
purestorage.flasharray        1.11.0
purestorage.flashblade        1.8.1
sensu.sensu_go                1.12.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.24.0
theforeman.foreman            2.2.0
vyos.vyos                     2.6.0
wti.remote                    1.0.3
```

### AWS SDK versions

```console (paste below)
$ pip show boto boto3 botocore

Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: mitch@garnaat.com
License: MIT
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.20.11
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.23.11
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer
```

### Configuration

```console (paste below)
$ ansible-config dump --only-changed

DEFAULT_CALLBACK_PLUGIN_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/plugins/callbacks']
DEFAULT_FILTER_PLUGIN_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/plugins/filters']
DEFAULT_FORKS(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = 55
DEFAULT_HOST_LIST(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/inventory/dev']
DEFAULT_INVENTORY_PLUGIN_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/plugins/inventory']
DEFAULT_JINJA2_EXTENSIONS(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = jinja2.ext.do
DEFAULT_LOOKUP_PLUGIN_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/plugins/lookups']
DEFAULT_MANAGED_STR(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = WARNING!!!! This file is managed by Ansible. Any changes will be overwritten.
DEFAULT_MODULE_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/library']
DEFAULT_ROLES_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/roles']
DEFAULT_STDOUT_CALLBACK(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = yaml
DEFAULT_TEST_PLUGIN_PATH(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['/Users/<USER>/Source/dataintelligence-ansible/plugins/tests']
DEFAULT_TIMEOUT(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = 30
HOST_KEY_CHECKING(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = False
INVENTORY_ANY_UNPARSED_IS_FAILED(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = True
INVENTORY_ENABLED(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ['host_list', 'script', 'meta']
TRANSFORM_INVALID_GROUP_CHARS(/Users/<USER>/Source/dataintelligence-ansible/ansible.cfg) = ignore
```

### OS / Environment

macOS 11.6

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test playbook
  hosts: localhost
  gather_facts: false
  vars:
    elb_definition:
      connection_draining_timeout: 5
      health_check:
        healthy_threshold: 5
        interval: 5
        ping_path: /verify/service/name/service-name
        ping_port: 8599
        ping_protocol: http
        response_timeout: 3
        unhealthy_threshold: 2
      listeners:
        - instance_port: 8691
          load_balancer_port: 443
          protocol: tcp
      name: dev-service-name
      region: us-east-1
      security_group_names:
        - sec-dev-admin
        - sec-dev
      state: present
      subnets:
        - subnet-...
        - subnet-...
      tags:
        CreatedBy: <USER>
        Lifecycle: dev
        Service: service-name

  tasks:
    - name: Create load balancer
      amazon.aws.elb_classic_lb: "{{ elb_definition }}"
      register: created_load_balancer
```


### Expected Results

Classic ELB named `dev-service-name` inside a VPC with 2 SGs attached

### Actual Results

**Error 1** (only happens when creating)
```console (paste below)
TASK [Create load balancer] *****************
task path: /Users/<USER>/Source/dataintelligence-ansible/playbooks/ansible-test/run.yml:36
Trying secret FileVaultSecret(filename='/Users/<USER>/Source/dataintelligence-ansible/.runtime/.vault/key') for vault_id=default
Trying secret FileVaultSecret(filename='/Users/<USER>/Source/dataintelligence-ansible/.runtime/.vault/key') for vault_id=default
[WARNING]: Using a variable for a task's 'args' is unsafe in some situations (see https://docs.ansible.com/ansible/devel/reference_appendices/faq.html#argsplat-unsafe)
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: <USER>
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/${USER}/.ansible `"&& mkdir "` echo /tmp/${USER}/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363 `" && echo ansible-tmp-1639541604.466327-10288-139306353191363="` echo /tmp/${USER}/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363 `" ) && sleep 0'
Using module file /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py
<127.0.0.1> PUT /Users/<USER>/.ansible/tmp/ansible-local-10266lu7jsxnd/tmp3l_s5jhl TO /private/tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/AnsiballZ_elb_classic_lb.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/ /tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/AnsiballZ_elb_classic_lb.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/bin/python3 /tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/AnsiballZ_elb_classic_lb.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => changed=false
  module_stderr: |-
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_m0o2m9ro/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_a903yonl/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_no7qlrkf/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_a903yonl/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_qle6i2iw/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_no7qlrkf/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    pydev debugger: warning: trying to add breakpoint to file that does not exist: /private/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_no7qlrkf/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py (will have no effect)
    Traceback (most recent call last):
      File "/tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/AnsiballZ_elb_classic_lb.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/tmp/<USER>/.ansible/ansible-tmp-1639541604.466327-10288-139306353191363/AnsiballZ_elb_classic_lb.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.amazon.aws.plugins.modules.elb_classic_lb', init_globals=dict(_module_fqn='ansible_collections.amazon.aws.plugins.modules.elb_classic_lb', _modlib_path=modlib_path),
      File "/Users/<USER>/.zinit/plugins/pyenv---pyenv/versions/3.9.8/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Users/<USER>/.zinit/plugins/pyenv---pyenv/versions/3.9.8/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Users/<USER>/.zinit/plugins/pyenv---pyenv/versions/3.9.8/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_i9z3wbt4/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py", line 2162, in <module>
      File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_i9z3wbt4/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py", line 2136, in main
      File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_i9z3wbt4/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py", line 749, in __init__
    AttributeError: 'NoneType' object has no attribute 'get'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1
```

**Error 2**
```console (paste below)
TASK [Create load balancer] **********************************
task path: /Users/<USER>/Source/dataintelligence-ansible/playbooks/ansible-test/run.yml:36
Trying secret FileVaultSecret(filename='/Users/<USER>/Source/dataintelligence-ansible/.runtime/.vault/key') for vault_id=default
Trying secret FileVaultSecret(filename='/Users/<USER>/Source/dataintelligence-ansible/.runtime/.vault/key') for vault_id=default
[WARNING]: Using a variable for a task's 'args' is unsafe in some situations (see https://docs.ansible.com/ansible/devel/reference_appendices/faq.html#argsplat-unsafe)
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: <USER>
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/${USER}/.ansible `"&& mkdir "` echo /tmp/${USER}/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304 `" && echo ansible-tmp-1639541896.763505-13068-156902109068304="` echo /tmp/${USER}/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304 `" ) && sleep 0'
Using module file /Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py
<127.0.0.1> PUT /Users/<USER>/.ansible/tmp/ansible-local-13053l5jw8hta/tmpy41u2b2z TO /private/tmp/<USER>/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304/AnsiballZ_elb_classic_lb.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/<USER>/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304/ /tmp/<USER>/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304/AnsiballZ_elb_classic_lb.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/bin/python3 /tmp/<USER>/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304/AnsiballZ_elb_classic_lb.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/<USER>/.ansible/ansible-tmp-1639541896.763505-13068-156902109068304/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_lanf_3ot/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py", line 930, in ensure_ok
  File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_lanf_3ot/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/modules/elb_classic_lb.py", line 876, in _create_elb
  File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_lanf_3ot/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/core.py", line 334, in deciding_wrapper
    return retrying_wrapper(*args, **kwargs)
  File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_lanf_3ot/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 118, in _retry_wrapper
    return _retry_func(
  File "/var/folders/tg/xnhm2vz535sfbxwn_vkggxpm0000gq/T/ansible_amazon.aws.elb_classic_lb_payload_lanf_3ot/ansible_amazon.aws.elb_classic_lb_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 68, in _retry_func
    return func()
  File "/Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/<USER>/Source/dataintelligence-ansible/.runtime/.pyvenv/lib/python3.9/site-packages/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidConfigurationRequestException: An error occurred (InvalidConfigurationRequest) when calling the CreateLoadBalancer operation: Security group "sg-..." does not belong to VPC "vpc-..."
fatal: [localhost]: FAILED! => changed=false
  boto3_version: 1.20.11
  botocore_version: 1.23.11
  error:
    code: InvalidConfigurationRequest
    message: Security group "sg-..." does not belong to VPC "vpc-..."
    type: Sender
  invocation:
    module_args:
      access_logs: null
      aws_access_key: null
      aws_ca_bundle: null
      aws_config: null
      aws_secret_key: null
      connection_draining_timeout: 5
      cross_az_load_balancing: null
      debug_botocore_endpoint_logs: false
      ec2_url: null
      health_check:
        healthy_threshold: 5
        interval: 5
        ping_path: /verify/service/name/service-name
        ping_port: 8599
        ping_protocol: http
        response_timeout: 3
        timeout: 3
        unhealthy_threshold: 2
      idle_timeout: null
      instance_ids: null
      listeners:
      - instance_port: 8691
        instance_protocol: null
        load_balancer_port: 443
        protocol: tcp
        proxy_protocol: null
        ssl_certificate_id: null
      name: dev-service-name
      profile: null
      purge_instance_ids: false
      purge_listeners: true
      purge_subnets: false
      purge_tags: true
      purge_zones: false
      region: us-east-1
      scheme: null
      security_group_ids: null
      security_group_names:
      - sec-dev-admin
      - sec-dev
      security_token: null
      state: present
      stickiness: null
      subnets:
      - subnet-...
      - subnet-...
      tags:
        CreatedBy: <USER>
        Lifecycle: dev
        Service: service-name
      validate_certs: true
      wait: false
      wait_timeout: 180
      zones: null
  msg: 'Failed to create load balancer: An error occurred (InvalidConfigurationRequest) when calling the CreateLoadBalancer operation: Security group "sg-..." does not belong to VPC "vpc-..."'
  response_metadata:
    http_headers:
      content-length: '370'
      content-type: text/xml
      date: Wed, 15 Dec 2021 04:21:26 GMT
      x-amzn-requestid: a50c6d9a-cad9-4885-a592-fd958b7e8831
    http_status_code: 409
    request_id: a50c6d9a-cad9-4885-a592-fd958b7e8831
    retry_attempts: 0
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
@anjo-swe Thank you for raising this issue. Would you be willing to open a PR to fix this issue?

Resolving patch:
diff --git a/plugins/modules/elb_classic_lb.py b/plugins/modules/elb_classic_lb.py
--- 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):


Test patch:
diff --git a/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml b/tests/integration/targets/elb_classic_lb/tasks/simple_instances.yml
--- 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