Repository: ansible-collections/amazon.aws

Issue:
ec2_vol: setting 'name' does not work, 'tags' is needed
### Summary

This used to work with version 3.2.0:
```
- name: Modify root volume
  local_action:
    module: ec2_vol
    region: "{{ region }}"
    modify_volume: yes
    instance: "{{ instance_id }}"
    name: "{{ ec2_name }}"
    volume_type: "{{ volume_type }}"
    iops: "{{ volume_iops | default(3000) }}"
    throughput: "{{ volume_throughput }}"
```
With version > 4.0.0 it errors now:
```
  File "/tmp/ansible_ec2_vol_payload_kjipke6j/ansible_ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py", line 869, in <module>
  File "/tmp/ansible_ec2_vol_payload_kjipke6j/ansible_ec2_vol_payload.zip/ansible_collections/amazon/aws/plugins/modules/ec2_vol.py", line 837, in main
TypeError: 'NoneType' object does not support item assignment
```
If I add line:
```
    tags: { 'Name': "{{ ec2_name }}" }
```
it works again. I see there is in the source:
```
            if name:
                tags['Name'] = name
```
but apparently it does not work?

### Issue Type

Bug Report

### Component Name

ec2_vol

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.12.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/nerijus/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/nerijus/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.7 (main, Sep  7 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-1)]
  jinja version = 3.0.3
  libyaml = True
```


### Collection Versions

```console (paste below)
$ ansible-galaxy collection list
# /usr/share/ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.posix     1.4.0  
community.docker  2.7.1  
community.general 4.8.3  
community.mysql   3.4.0  
containers.podman 1.9.4  
google.cloud      1.0.2  

# /home/nerijus/.ansible/collections/ansible_collections
Collection             Version
---------------------- -------
amazon.aws             4.2.0  
ansible.netcommon      3.1.1  
ansible.posix          1.4.0  
ansible.utils          2.6.1  
ansible.windows        1.11.1 
community.aws          4.2.0  
community.crypto       2.0.1  
community.digitalocean 1.12.0 
community.general      5.6.0  
community.grafana      1.2.1  
community.mysql        3.5.1  
community.postgresql   2.2.0  
community.rabbitmq     1.0.1  
community.zabbix       1.8.0  
hetzner.hcloud         1.6.0  
```


### 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: /usr/lib/python3.10/site-packages
Requires: 
Required-by: 
---
Name: boto3
Version: 1.21.33
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.10/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.24.33
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.10/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: awscli, boto3, s3transfer

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

CACHE_PLUGIN(/home/nerijus/ansible-advbet/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/nerijus/ansible-advbet/ansible.cfg) = ~/.cache/ansible-facts
CACHE_PLUGIN_TIMEOUT(/home/nerijus/ansible-advbet/ansible.cfg) = 86400
DEFAULT_ACTION_PLUGIN_PATH(/home/nerijus/ansible-advbet/ansible.cfg) = ['/home/nerijus/.local/lib/python3.*/*-packages/ara/plugins/action', '/usr/lib/python3.*/*-packages/ara/plugins/action', '/usr/local/lib/python*/*-packages/ara/plugins/action']
DEFAULT_CALLBACK_PLUGIN_PATH(/home/nerijus/ansible-advbet/ansible.cfg) = ['/home/nerijus/.local/lib/python3.*/*-packages/ara/plugins/callback', '/usr/lib/python3.*/*-packages/ara/plugins/callback', '/usr/local/lib/python*/*-packages/ara/plugins/callback']
DEFAULT_GATHERING(/home/nerijus/ansible-advbet/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/nerijus/ansible-advbet/ansible.cfg) = ['/home/nerijus/ansible-advbet/inventory/ops/hosts']
DEFAULT_LOOKUP_PLUGIN_PATH(/home/nerijus/ansible-advbet/ansible.cfg) = ['/home/nerijus/.local/lib/python3.*/*-packages/ara/plugins/lookup', '/usr/lib/python3.*/*-packages/ara/plugins/lookup', '/usr/local/lib/python*/*-packages/ara/plugins/lookup']
DEFAULT_REMOTE_USER(/home/nerijus/ansible-advbet/ansible.cfg) = root
DEFAULT_ROLES_PATH(/home/nerijus/ansible-advbet/ansible.cfg) = ['/home/nerijus/ansible-advbet/roles']
DEFAULT_STDOUT_CALLBACK(/home/nerijus/ansible-advbet/ansible.cfg) = debug
DISPLAY_SKIPPED_HOSTS(/home/nerijus/ansible-advbet/ansible.cfg) = False
MAX_FILE_SIZE_FOR_DIFF(/home/nerijus/ansible-advbet/ansible.cfg) = 0
```


### OS / Environment

Fedora 36

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

- name: Modify root volume
  local_action:
    module: ec2_vol
    region: "{{ region }}"
    modify_volume: yes
    instance: "{{ instance_id }}"
    name: "{{ ec2_name }}"
    volume_type: "{{ volume_type }}"
    iops: "{{ volume_iops | default(3000) }}"
    throughput: "{{ volume_throughput }}"
```


### Expected Results

It should not error.

### Actual Results

```console (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/ec2_vol.py`](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/ec2_vol.py)

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 --->
cc @jillr @lwade @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_vol.py b/plugins/modules/ec2_vol.py
--- a/plugins/modules/ec2_vol.py
+++ b/plugins/modules/ec2_vol.py
@@ -811,7 +811,6 @@ def main():
             mapped_device = get_mapped_block_device(instance_dict=inst, device_name=device_name)
             if mapped_device:
                 other_volume_mapped = False
-
                 if volume:
                     if volume['volume_id'] != mapped_device['ebs']['volume_id']:
                         other_volume_mapped = True
@@ -830,10 +829,11 @@ def main():
 
         final_tags = None
         tags_changed = False
-
         if volume:
             volume, changed = update_volume(module, ec2_conn, volume)
             if name:
+                if not tags:
+                    tags = boto3_tag_list_to_ansible_dict(volume.get('tags'))
                 tags['Name'] = name
             final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, module.params.get('purge_tags'))
         else:


Test patch:
diff --git a/tests/integration/targets/ec2_vol/tasks/main.yml b/tests/integration/targets/ec2_vol/tasks/main.yml
--- a/tests/integration/targets/ec2_vol/tasks/main.yml
+++ b/tests/integration/targets/ec2_vol/tasks/main.yml
@@ -61,6 +61,21 @@
         that:
           - test_instance_2.changed
 
+    - name: create another ec2 instance
+      ec2_instance:
+        name: "{{ instance_name }}-3"
+        vpc_subnet_id: "{{ testing_subnet.subnet.id }}"
+        instance_type: t3.nano
+        image_id: "{{ ec2_ami_id }}"
+        tags:
+          ResourcePrefix: "{{ resource_prefix }}"
+      register: test_instance_3
+
+    - name: check task return attributes
+      assert:
+        that:
+          - test_instance_3.changed
+
     # # ==== ec2_vol tests ===============================================
 
     - name: create a volume (validate module defaults - check_mode)
@@ -852,6 +867,28 @@
           - 'test_instance.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list'
           - 'test_instance_2.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list'
 
+    - name: create a volume without tags
+      ec2_vol:
+        volume_size: 5
+        zone: "{{ availability_zone }}"
+        instance: "{{ test_instance_3.instance_ids[0] }}"
+      register: volume_without_tag
+
+    - assert:
+        that:
+          - volume_without_tag.changed
+
+    # idempotency check without tags
+    - name: create a volume without tags (idempotency check)
+      ec2_vol:
+        volume_size: 5
+        zone: "{{ availability_zone }}"
+        instance: "{{ test_instance_3.instance_ids[0] }}"
+      register: volume_without_tag
+
+    - assert:
+        that:
+          - not volume_without_tag.changed
     # ==== Cleanup ============================================================
 
   always:
@@ -863,6 +900,7 @@
       with_items:
         - "{{ test_instance.instance_ids[0] }}"
         - "{{ test_instance_2.instance_ids[0] }}"
+        - "{{ test_instance_3.instance_ids[0] }}"
       register: pre_delete
 
     - debug:
@@ -877,6 +915,7 @@
       with_items:
         - "{{ test_instance.instance_ids[0] }}"
         - "{{ test_instance_2.instance_ids[0] }}"
+        - "{{ test_instance_3.instance_ids[0] }}"
       ignore_errors: yes
 
     - name: delete volumes
@@ -893,6 +932,7 @@
         - "{{ dot_volume }}"
         - "{{ gp3_volume }}"
         - "{{ multi_attach_disk }}"
+        - "{{ volume_without_tag }}"
 
     - name: delete snapshot
       ec2_snapshot: