Repository: ansible-collections/amazon.aws

Issue:
amazon.aws.ec2_instance volumes does not support snapshot_id
### Summary

When trying to spin up a set of ec2 instances; we need to use a snapshot as a volume attachment

the amazon.aws.ec2 module supports attaching a snapshot id but not kms_id and the newer amazon.aws.ec2_instance does not seem to support snapshot_id but does support kms_id

How does one spin up new instances with an attached volume from a snapshot?

### Issue Type

Bug Report

### Component Name

amazon.aws.ec2_instance

### Ansible Version

```console (paste below)
$ ansible --version

ansible [core 2.12.4]
  config file = /Users/bob/p/stuff/spikes/tes-yocto-devenvs/ansible.cfg
  configured module search path = ['/Users/bob/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/5.6.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/bob/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.2 (main, Feb  2 2022, 07:36:01) [Clang 12.0.0 (clang-1200.0.32.29)]
  jinja version = 3.1.1
  libyaml = True
```


### Collection Versions

```console (paste below)
$ ansible-galaxy collection list
Collection    Version
------------- -------
amazon.aws    3.2.0
community.aws 3.2.1
```


### AWS SDK versions

```console (paste below)
$ pip show boto boto3 botocore

pip3 show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.17.18
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/bob/Library/Python/3.9/lib/python/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.20.18
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/bob/Library/Python/3.9/lib/python/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed


Collection                    Version
----------------------------- -------
amazon.aws                    2.2.0
ansible.netcommon             2.6.1
ansible.posix                 1.3.0
ansible.utils                 2.5.2
ansible.windows               1.9.0
arista.eos                    3.1.0
awx.awx                       19.4.0
azure.azcollection            1.12.0
check_point.mgmt              2.3.0
chocolatey.chocolatey         1.2.0
cisco.aci                     2.2.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.8.1
cisco.iosxr                   2.9.0
cisco.ise                     1.2.1
cisco.meraki                  2.6.1
cisco.mso                     1.4.0
cisco.nso                     1.0.3
cisco.nxos                    2.9.1
cisco.ucs                     1.8.0
cloud.common                  2.1.0
cloudscale_ch.cloud           2.2.1
community.aws                 2.4.0
community.azure               1.1.0
community.ciscosmb            1.0.4
community.crypto              2.2.4
community.digitalocean        1.16.0
community.dns                 2.0.9
community.docker              2.3.0
community.fortios             1.0.0
community.general             4.7.0
community.google              1.0.0
community.grafana             1.3.3
community.hashi_vault         2.4.0
community.hrobot              1.2.3
community.kubernetes          2.0.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.3
community.mysql               2.3.5
community.network             3.1.0
community.okd                 2.1.0
community.postgresql          1.7.1
community.proxysql            1.3.1
community.rabbitmq            1.1.0
community.routeros            2.0.0
community.sap                 1.0.0
community.skydive             1.0.0
community.sops                1.2.1
community.vmware              1.18.0
community.windows             1.9.0
community.zabbix              1.5.1
containers.podman             1.9.3
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            4.4.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.15.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.4
frr.frr                       1.0.3
gluster.gluster               1.0.2
google.cloud                  1.0.2
hetzner.hcloud                1.6.0
hpe.nimble                    1.1.4
ibm.qradar                    1.0.3
infinidat.infinibox           1.3.3
infoblox.nios_modules         1.2.1
inspur.sm                     1.3.0
junipernetworks.junos         2.10.0
```


### OS / Environment

osx

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```


### Expected Results

an ec2 instance spins up with a volume from a snapshot_id

### Actual Results

```console (paste below)

```


### 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 --->
Hi @rosscdh, Thank you for opening this issue.
I tried a couple of example tasks that make use of a `snapshot_id` to attach the volume from a snapshot while spinning up the new instances.
The below seem to work as expected, could you please try using something like this to see if it works for your case.

```
- name: Create a test instances with snapshot volumes attached to it
  tasks:
  
    - name: start single instance
      amazon.aws.ec2_instance:
        name: "test-instance"
        vpc_subnet_id: subnet-xxxxxxxxx
        instance_type: t3.small
        image_id: ami-00399xxxxxxxxx
        volumes:
        - device_name: /dev/sda2
          ebs:
            snapshot_id: snap-0xxxxxxxx

    - name: start multiple instances
      amazon.aws.ec2_instance:
        name: "test-instance-{{ item }}"
        vpc_subnet_id: subnet-xxxxxxxxx
        instance_type: t3.small
        image_id: ami-00399xxxxxxxxx
        volumes:
        - device_name: /dev/sda2
          ebs:
            snapshot_id: snap-0xxxxxxxx
      with_items: [1,2,3]
```

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
@@ -206,7 +206,7 @@
     description:
     - A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage.
     - A mapping contains the (optional) keys device_name, virtual_name, ebs.volume_type, ebs.volume_size, ebs.kms_key_id,
-      ebs.iops, and ebs.delete_on_termination.
+      ebs.snapshot_id, ebs.iops, and ebs.delete_on_termination.
     - For more information about each parameter, see U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html).
     type: list
     elements: dict
@@ -396,6 +396,17 @@
           volume_size: 16
           delete_on_termination: true
 
+- name: start an instance and Add EBS volume from a snapshot
+  amazon.aws.ec2_instance:
+    name: "public-withebs-instance"
+    instance_type: t2.micro
+    image_id: ami-1234567890
+    vpc_subnet_id: subnet-5ca1ab1e
+    volumes:
+      - device_name: /dev/sda2
+        ebs:
+          snapshot_id: snap-1234567890
+
 - name: start an instance with a cpu_options
   amazon.aws.ec2_instance:
     name: "public-cpuoption-instance"


Test patch: