diff --git a/moto/ec2/responses/elastic_block_store.py b/moto/ec2/responses/elastic_block_store.py index f7f4df9dc..853af936d 100644 --- a/moto/ec2/responses/elastic_block_store.py +++ b/moto/ec2/responses/elastic_block_store.py @@ -19,10 +19,13 @@ class ElasticBlockStore(BaseResponse): source_snapshot_id = self._get_param("SourceSnapshotId") source_region = self._get_param("SourceRegion") description = self._get_param("Description") + tags = self._parse_tag_specification("TagSpecification") + snapshot_tags = tags.get("snapshot", {}) if self.is_not_dryrun("CopySnapshot"): snapshot = self.ec2_backend.copy_snapshot( source_snapshot_id, source_region, description ) + snapshot.add_tags(snapshot_tags) template = self.response_template(COPY_SNAPSHOT_RESPONSE) return template.render(snapshot=snapshot) @@ -272,6 +275,16 @@ CREATE_SNAPSHOT_RESPONSE = """ 59dbff89-35bd-4eac-99ed-be587EXAMPLE {{ snapshot.id }} + + {% for tag in snapshot.get_tags() %} + + {{ tag.resource_id }} + {{ tag.resource_type }} + {{ tag.key }} + {{ tag.value }} + + {% endfor %} + """ DESCRIBE_SNAPSHOTS_RESPONSE = """ diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index 7f8313da4..ef140b06e 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -9,7 +9,6 @@ import boto import boto3 from botocore.exceptions import ClientError from boto.exception import EC2ResponseError -from freezegun import freeze_time import sure # noqa from moto import mock_ec2_deprecated, mock_ec2 @@ -834,22 +833,26 @@ def test_volume_property_hidden_when_no_tags_exist(): volume_response.get("Tags").should.equal(None) -@freeze_time @mock_ec2 def test_copy_snapshot(): ec2_client = boto3.client("ec2", region_name="eu-west-1") dest_ec2_client = boto3.client("ec2", region_name="eu-west-2") volume_response = ec2_client.create_volume(AvailabilityZone="eu-west-1a", Size=10) + tag_spec = [ + {"ResourceType": "snapshot", "Tags": [{"Key": "key", "Value": "value"}]} + ] create_snapshot_response = ec2_client.create_snapshot( - VolumeId=volume_response["VolumeId"] + VolumeId=volume_response["VolumeId"], TagSpecifications=tag_spec ) copy_snapshot_response = dest_ec2_client.copy_snapshot( SourceSnapshotId=create_snapshot_response["SnapshotId"], SourceRegion="eu-west-1", + TagSpecifications=tag_spec, ) + copy_snapshot_response["Tags"].should.equal(tag_spec[0]["Tags"]) ec2 = boto3.resource("ec2", region_name="eu-west-1") dest_ec2 = boto3.resource("ec2", region_name="eu-west-2")