diff --git a/moto/ec2/models.py b/moto/ec2/models.py
index 1454e1a1c..6008ed24c 100644
--- a/moto/ec2/models.py
+++ b/moto/ec2/models.py
@@ -127,6 +127,7 @@ from .utils import (
random_ipv6_cidr,
random_transit_gateway_attachment_id,
random_transit_gateway_route_table_id,
+ random_vpc_ep_id,
randor_ipv4_cidr,
random_launch_template_id,
random_nat_gateway_id,
@@ -137,7 +138,6 @@ from .utils import (
random_reservation_id,
random_route_table_id,
generate_route_id,
- generate_vpc_end_point_id,
create_dns_entries,
split_route_id,
random_security_group_id,
@@ -3267,11 +3267,11 @@ class VPCBackend(object):
dns_entries=None,
client_token=None,
security_group_ids=None,
- tag_specifications=None,
+ tags=None,
private_dns_enabled=None,
):
- vpc_endpoint_id = generate_vpc_end_point_id(vpc_id)
+ vpc_endpoint_id = random_vpc_ep_id()
# validates if vpc is present or not.
self.get_vpc(vpc_id)
@@ -3308,7 +3308,7 @@ class VPCBackend(object):
dns_entries,
client_token,
security_group_ids,
- tag_specifications,
+ tags,
private_dns_enabled,
)
@@ -3378,10 +3378,12 @@ class PeeringConnectionStatus(object):
class VPCPeeringConnection(TaggedEC2Resource, CloudFormationModel):
- def __init__(self, vpc_pcx_id, vpc, peer_vpc):
+ def __init__(self, backend, vpc_pcx_id, vpc, peer_vpc, tags=None):
self.id = vpc_pcx_id
+ self.ec2_backend = backend
self.vpc = vpc
self.peer_vpc = peer_vpc
+ self.add_tags(tags or {})
self._status = PeeringConnectionStatus()
@staticmethod
@@ -3428,9 +3430,9 @@ class VPCPeeringConnectionBackend(object):
if inst is not None:
yield inst
- def create_vpc_peering_connection(self, vpc, peer_vpc):
+ def create_vpc_peering_connection(self, vpc, peer_vpc, tags=None):
vpc_pcx_id = random_vpc_peering_connection_id()
- vpc_pcx = VPCPeeringConnection(vpc_pcx_id, vpc, peer_vpc)
+ vpc_pcx = VPCPeeringConnection(self, vpc_pcx_id, vpc, peer_vpc, tags)
vpc_pcx._status.pending()
self.vpc_pcxs[vpc_pcx_id] = vpc_pcx
# insert cross region peering info
@@ -4362,7 +4364,7 @@ class VPCEndPoint(TaggedEC2Resource):
dns_entries=None,
client_token=None,
security_group_ids=None,
- tag_specifications=None,
+ tags=None,
private_dns_enabled=None,
):
self.ec2_backend = ec2_backend
@@ -4376,10 +4378,14 @@ class VPCEndPoint(TaggedEC2Resource):
self.subnet_ids = subnet_ids
self.client_token = client_token
self.security_group_ids = security_group_ids
- self.tag_specifications = tag_specifications
self.private_dns_enabled = private_dns_enabled
- self.created_at = datetime.utcnow()
+ self._created_at = datetime.utcnow()
self.dns_entries = dns_entries
+ self.add_tags(tags or {})
+
+ @property
+ def created_at(self):
+ return iso_8601_datetime_with_milliseconds(self._created_at)
class RouteBackend(object):
diff --git a/moto/ec2/responses/vpc_peering_connections.py b/moto/ec2/responses/vpc_peering_connections.py
index 84dbf2bf5..718dfcb5c 100644
--- a/moto/ec2/responses/vpc_peering_connections.py
+++ b/moto/ec2/responses/vpc_peering_connections.py
@@ -6,6 +6,11 @@ from moto.core import ACCOUNT_ID
class VPCPeeringConnections(BaseResponse):
def create_vpc_peering_connection(self):
peer_region = self._get_param("PeerRegion")
+ tags = self._get_multi_param("TagSpecification")
+ tags = tags[0] if isinstance(tags, list) and len(tags) == 1 else tags
+ tags = (tags or {}).get("Tag", [])
+ tags = {t["Key"]: t["Value"] for t in tags}
+
if peer_region == self.region or peer_region is None:
peer_vpc = self.ec2_backend.get_vpc(self._get_param("PeerVpcId"))
else:
@@ -13,7 +18,7 @@ class VPCPeeringConnections(BaseResponse):
self._get_param("PeerVpcId"), peer_region
)
vpc = self.ec2_backend.get_vpc(self._get_param("VpcId"))
- vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc)
+ vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc, tags)
template = self.response_template(CREATE_VPC_PEERING_CONNECTION_RESPONSE)
return template.render(vpc_pcx=vpc_pcx)
@@ -68,7 +73,14 @@ CREATE_VPC_PEERING_CONNECTION_RESPONSE = (
Initiating Request to {accepter ID}
2014-02-18T14:37:25.000Z
-
+
+ {% for tag in vpc_pcx.get_tags() %}
+ -
+ {{ tag.key }}
+ {{ tag.value }}
+
+ {% endfor %}
+
"""
@@ -105,7 +117,14 @@ DESCRIBE_VPC_PEERING_CONNECTIONS_RESPONSE = (
{{ vpc_pcx._status.code }}
{{ vpc_pcx._status.message }}
-
+
+ {% for tag in vpc_pcx.get_tags() %}
+ -
+ {{ tag.key }}
+ {{ tag.value }}
+
+ {% endfor %}
+
{% endfor %}
@@ -149,7 +168,14 @@ ACCEPT_VPC_PEERING_CONNECTION_RESPONSE = (
{{ vpc_pcx._status.code }}
{{ vpc_pcx._status.message }}
-
+
+ {% for tag in vpc_pcx.get_tags() %}
+ -
+ {{ tag.key }}
+ {{ tag.value }}
+
+ {% endfor %}
+
"""
diff --git a/moto/ec2/responses/vpcs.py b/moto/ec2/responses/vpcs.py
index 06ebce63f..121dcba11 100644
--- a/moto/ec2/responses/vpcs.py
+++ b/moto/ec2/responses/vpcs.py
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
from moto.core import ACCOUNT_ID
from moto.core.responses import BaseResponse
from moto.core.utils import camelcase_to_underscores
-from moto.ec2.utils import filters_from_querystring
+from moto.ec2.utils import add_tag_specification, filters_from_querystring
class VPCs(BaseResponse):
@@ -184,10 +184,11 @@ class VPCs(BaseResponse):
type = self._get_param("VpcEndpointType")
policy_document = self._get_param("PolicyDocument")
client_token = self._get_param("ClientToken")
- tag_specifications = self._get_param("TagSpecifications")
+ tags = self._get_multi_param("TagSpecification")
private_dns_enabled = self._get_bool_param("PrivateDnsEnabled", if_none=True)
security_group_ids = self._get_multi_param("SecurityGroupId")
+ tags = add_tag_specification(tags)
vpc_end_point = self.ec2_backend.create_vpc_endpoint(
vpc_id=vpc_id,
service_name=service_name,
@@ -197,10 +198,9 @@ class VPCs(BaseResponse):
subnet_ids=subnet_ids,
client_token=client_token,
security_group_ids=security_group_ids,
- tag_specifications=tag_specifications,
+ tags=tags,
private_dns_enabled=private_dns_enabled,
)
-
template = self.response_template(CREATE_VPC_END_POINT)
return template.render(vpc_end_point=vpc_end_point)
@@ -483,6 +483,14 @@ CREATE_VPC_END_POINT = """