Repository: ansible-collections/amazon.aws

Issue:
amazon.aws.ec2_instance throws deprecation warning for teardown
### Summary

There is a 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."  I think this makes sense, except that this particular module does not need the instance_type set at all if you are doing `state: absent`.  I am not sure if we just document this... or if the warning needs to be clear to ignore if you are doing state: absent, or if we can be smart enough to not display the warning if you are doing state: absent.

### Issue Type

Bug Report

### Component Name

amazon.aws.ec2_instance

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.12.2]
  config file = /Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg
  configured module search path = ['/Users/sean/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/sean/Documents/GitHub/IPvSean/workshops/feb21/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/sean/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/sean/Documents/GitHub/IPvSean/workshops/feb21/bin/ansible
  python version = 3.9.9 (main, Nov 21 2021, 03:23:42) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.0.3
  libyaml = True
```


### Collection Versions

```console (paste below)
(feb21) ➜  provisioner git:(gh-pages) ✗  ansible-galaxy collection list

# /Users/sean/.ansible/collections/ansible_collections
Collection                          Version
----------------------------------- -------
amazon.aws                          3.1.1
ansible.netcommon                   2.0.2
ansible.posix                       1.2.0
ansible.product_demos               1.2.12
ansible.utils                       2.5.0
ansible.windows                     1.5.0
ansible.workshops                   1.0.11
arista.eos                          2.1.2
awx.awx                             19.4.0
chocolatey.chocolatey               1.1.0
cisco.ios                           2.0.1
community.aws                       1.5.0
community.crypto                    1.6.2
community.general                   3.0.2
community.mysql                     2.1.0
community.windows                   1.3.0
containers.podman                   1.9.1
f5networks.f5_modules               1.9.0
junipernetworks.junos               2.1.0
redhat_cop.controller_configuration 2.1.1
redhat_cop.tower_utilities          2.0.1
```


### AWS SDK versions

```console (paste below)
(feb21) ➜  provisioner git:(gh-pages) ✗ pip show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.21.3
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/sean/Documents/GitHub/IPvSean/workshops/feb21/lib/python3.9/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.24.3
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/sean/Documents/GitHub/IPvSean/workshops/feb21/lib/python3.9/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer
```


### Configuration

```console (paste below)
DEFAULT_FORKS(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 50
DEFAULT_HOST_LIST(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = ['/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/hosts']
DEFAULT_STDOUT_CALLBACK(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = yaml
HOST_KEY_CHECKING(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 60
PERSISTENT_CONNECT_TIMEOUT(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = 60
RETRY_FILES_ENABLED(/Users/sean/Documents/GitHub/IPvSean/workshops/provisioner/ansible.cfg) = False

```


### OS / Environment

MacOS Big Sur Version 11.6.1

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
# Destroy VPC 2 instances for network automation
- name: destroy EC2 instances (VPC2)
  amazon.aws.ec2_instance:
    region: "{{ ec2_region }}"
    state: absent
    instance_ids: "{{ all_workshop_vpc2_nodes.instances | map(attribute='instance_id') | list }}"
    wait: true
    wait_timeout: "{{ student_total * 300 | int}}"
  register: result_ec2_destroy2
  when:
    - ec2_vpc_id2 is defined
    - all_workshop_vpc2_nodes.instances
```


### Expected Results

No purple warning

### Actual Results

```console (paste below)
TASK [../roles/manage_ec2_instances : destroy EC2 instances (VPC2)] *****************************************************************************************************************************************************************************
[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.
changed: [localhost]

```


### Code of Conduct

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


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@IPvSean Thank you for raising this. I guess we can easily reduce the scope of this warning to specific states. Do you agree @jillr?

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
@@ -1973,7 +1973,7 @@ def main():
         supports_check_mode=True
     )
 
-    if not module.params.get('instance_type') and not module.params.get('launch_template'):
+    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')
     result = dict()


Test patch: