diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 633968d2d..8b03efb6d 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -5773,7 +5773,7 @@ class CustomerGatewayBackend(object): class NatGateway(CloudFormationModel): - def __init__(self, backend, subnet_id, allocation_id): + def __init__(self, backend, subnet_id, allocation_id, tags=[]): # public properties self.id = random_nat_gateway_id() self.subnet_id = subnet_id @@ -5791,6 +5791,7 @@ class NatGateway(CloudFormationModel): # associate allocation with ENI self._backend.associate_address(eni=self._eni, allocation_id=self.allocation_id) + self.tags = tags @property def vpc_id(self): @@ -5867,8 +5868,8 @@ class NatGatewayBackend(object): return nat_gateways - def create_nat_gateway(self, subnet_id, allocation_id): - nat_gateway = NatGateway(self, subnet_id, allocation_id) + def create_nat_gateway(self, subnet_id, allocation_id, tags=[]): + nat_gateway = NatGateway(self, subnet_id, allocation_id, tags) self.nat_gateways[nat_gateway.id] = nat_gateway return nat_gateway diff --git a/moto/ec2/responses/nat_gateways.py b/moto/ec2/responses/nat_gateways.py index efa5c2656..398645966 100644 --- a/moto/ec2/responses/nat_gateways.py +++ b/moto/ec2/responses/nat_gateways.py @@ -7,8 +7,11 @@ class NatGateways(BaseResponse): def create_nat_gateway(self): subnet_id = self._get_param("SubnetId") allocation_id = self._get_param("AllocationId") + tags = self._get_multi_param("TagSpecification") + if tags: + tags = tags[0].get("Tag") nat_gateway = self.ec2_backend.create_nat_gateway( - subnet_id=subnet_id, allocation_id=allocation_id + subnet_id=subnet_id, allocation_id=allocation_id, tags=tags ) template = self.response_template(CREATE_NAT_GATEWAY) return template.render(nat_gateway=nat_gateway) @@ -44,6 +47,16 @@ DESCRIBE_NAT_GATEWAYS_RESPONSE = """