Repository: ansible-collections/amazon.aws

Issue:
ec2_instance: instance_type should not be required to start/stop instances
### Summary

Hello,

I have some old ansible scripts using the old `ec2` module that I'm updating to use the new `ec2_instance` module and I'm getting some deprecation warnings that I think don't really make sense. What I'm essentially trying to do is to start/stop instances matching a tag. I have these scripts to do this:

```yaml
- name: turn on instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: running
    purge_tags: false
```

and 

```yaml
- name: shut down instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: stopped
    purge_tags: false
```

When I run these I get this deprecation warning:

```console
[DEPRECATION WARNING]: Default value instance_type has been deprecated, in the 
future you must set an instance_type or a launch_template. This feature will be
removed from amazon.aws in a release after 2023-01-01. Deprecation warnings 
can be disabled by setting deprecation_warnings=False in ansible.cfg.
```

However, requiring `instance_type` doesn't really make much sense to me becasue I'm not trying to create, re-create or re-size any instances. I'm just tring to turn them on and off. Even specifying a dummy value would be a bit weird since the intances I'm turning on/off are of various sizes.

Examining the code, it looks like the warning is given for any state that is not `absent`: https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L2053

I think the specifying `instance_type` or `launch_template` should only be required if you also specify `count` or `exact_count`, since that would be the only time new instances would or could be launched. If neither is present, then `instance_type` is not needed as far as I can tell.

So, I propose that the conditional for the warning be change to something like:

```python
if not module.params.get('instance_type') and not module.params.get('launch_template'):
    if module.params.get('state') not in ('absent', 'stopped'):
        if module.params.get('size') or module.params.get('exact_size'):
           module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template",
                            date='2023-01-01', collection_name='amazon.aws')
```

Let me know if this is acceptable or if you have other ideas or comments. I could prepare a patch if my suggestion is acceptable.

### Issue Type

Bug Report

### Component Name

ec2_instance

### Ansible Version

```console
ansible 2.10.8
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]
```


### Collection Versions

```console
# /usr/lib/python3/dist-packages/ansible_collections
Collection                Version
------------------------- -------
amazon.aws                1.4.0
ansible.netcommon         1.5.0
ansible.posix             1.1.1
ansible.windows           1.4.0
arista.eos                1.3.0
awx.awx                   14.1.0
azure.azcollection        1.4.0
check_point.mgmt          1.0.6
chocolatey.chocolatey     1.0.2
cisco.aci                 1.1.1
cisco.asa                 1.0.4
cisco.intersight          1.0.10
cisco.ios                 1.3.0
cisco.iosxr               1.2.1
cisco.meraki              2.2.0
cisco.mso                 1.1.0
cisco.nso                 1.0.3
cisco.nxos                1.4.0
cisco.ucs                 1.6.0
cloudscale_ch.cloud       1.3.1
community.aws             1.3.0
community.azure           1.0.0
community.crypto          1.4.0
community.digitalocean    1.0.0
community.docker          1.2.2
community.fortios         1.0.0
community.general         1.3.6
community.google          1.0.0
community.grafana         1.1.0
community.hashi_vault     1.1.0
community.hrobot          1.1.0
community.kubernetes      1.1.1
community.kubevirt        1.0.0
community.libvirt         1.0.0
community.mongodb         1.2.0
community.mysql           1.2.0
community.network         1.3.2
community.okd             1.0.0
community.postgresql      1.1.1
community.proxysql        1.0.0
community.rabbitmq        1.0.1
community.routeros        1.1.0
community.skydive         1.0.0
community.vmware          1.7.0
community.windows         1.3.0
community.zabbix          1.2.0
containers.podman         1.4.1
cyberark.conjur           1.1.0
cyberark.pas              1.0.5
dellemc.os10              1.0.2
dellemc.os6               1.0.6
dellemc.os9               1.0.3
f5networks.f5_modules     1.7.1
fortinet.fortimanager     1.0.5
fortinet.fortios          1.1.8
frr.frr                   1.0.3
gluster.gluster           1.0.1
google.cloud              1.0.2
hetzner.hcloud            1.2.1
ibm.qradar                1.0.3
infinidat.infinibox       1.2.4
junipernetworks.junos     1.3.0
mellanox.onyx             1.0.0
netapp.aws                20.9.0
netapp.elementsw          20.11.0
netapp.ontap              20.12.0
netapp_eseries.santricity 1.1.0
netbox.netbox             1.2.1
ngine_io.cloudstack       1.2.0
ngine_io.exoscale         1.0.0
ngine_io.vultr            1.1.0
openstack.cloud           1.2.1
openvswitch.openvswitch   1.1.0
ovirt.ovirt               1.3.0
purestorage.flasharray    1.6.2
purestorage.flashblade    1.4.0
servicenow.servicenow     1.0.4
splunk.es                 1.0.2
theforeman.foreman        1.5.1
vyos.vyos                 1.1.1
wti.remote                1.0.1

# /usr/share/ansible/collections/ansible_collections
Collection    Version
------------- -------
amazon.aws    4.1.0
community.aws 4.1.1

```


### AWS SDK versions

```console
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: /usr/lib/python3/dist-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.20.34
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: /usr/lib/python3/dist-packages
Requires:
Required-by:
---
Name: botocore
Version: 1.23.34
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: /usr/lib/python3/dist-packages
Requires:
Required-by:

```


### Configuration

```console
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/etc/ansible/ansible.cfg) = ['aws_ec2', 'host_list', 'ini', 'yaml', 'constructed']
```

### OS / Environment

Ubuntu 22.04

### Steps to Reproduce

```yaml
- name: turn on instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: running
    purge_tags: false

- name: shut down instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: stopped
    purge_tags: false
```


### Expected Results

Tasks run with no warning or depracations.

### Actual Results

```console
[DEPRECATION WARNING]: Default value instance_type has been deprecated, in the 
future you must set an instance_type or a launch_template. This feature will be
removed from amazon.aws in a release after 2023-01-01. Deprecation warnings 
can be disabled by setting deprecation_warnings=False in ansible.cfg.
```


### Code of Conduct

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


Discussion:
@rbobrowicz Thank you for bringing this. Feel free to open a pull request with this contribution. Add [a changelog fragment](https://docs.ansible.com/ansible/latest/community/development_process.html#creating-changelog-fragments) also please.
cc @jillr @ryansb @s-hertel @tremble
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py
--- a/plugins/modules/ec2_instance.py
+++ b/plugins/modules/ec2_instance.py
@@ -2050,9 +2050,11 @@ def main():
         supports_check_mode=True
     )
 
-    if not module.params.get('instance_type') and not module.params.get('launch_template') and module.params.get('state') != 'absent':
-        module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template",
-                         date='2023-01-01', collection_name='amazon.aws')
+    if not module.params.get('instance_type') and not module.params.get('launch_template'):
+        if module.params.get('state') not in ('absent', 'stopped'):
+            if module.params.get('count') or module.params.get('exact_count'):
+                module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template",
+                                 date='2023-01-01', collection_name='amazon.aws')
     result = dict()
 
     if module.params.get('network'):


Test patch: